summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Build/source/texk/web2c/luatexdir/ChangeLog13
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/liolib.c14
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/loslibext.c6
-rw-r--r--Build/source/texk/web2c/luatexdir/luascripts/txt2zlib.w2
-rw-r--r--Build/source/texk/web2c/luatexdir/luatex.c77
-rw-r--r--Build/source/texk/web2c/luatexdir/luatex.h2
-rw-r--r--Build/source/texk/web2c/luatexdir/tex/texfileio.w22
7 files changed, 83 insertions, 53 deletions
diff --git a/Build/source/texk/web2c/luatexdir/ChangeLog b/Build/source/texk/web2c/luatexdir/ChangeLog
index 22abc020877..0d5d960fdc2 100644
--- a/Build/source/texk/web2c/luatexdir/ChangeLog
+++ b/Build/source/texk/web2c/luatexdir/ChangeLog
@@ -1,3 +1,16 @@
+2012-07-09 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ * tex/texfileio.w (runpopen): Sync with ../lib/texmfmp.c.
+
+2012-07-07 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ * luatex.c (shell_cmd_is_allowed): Change Arg1 from 'const char **'
+ into 'const char *'; sync with ../lib/texmfmp.c.
+ * luatex.h, lua/liolib.c, lua/loslibext.c, tex/texfileio.w: Adapt.
+
+ * lua/liolib.c, luascripts/txt2zlib.w: Use binary file io mode.
+ From Akira Kakuto <kakuto@fuk.kindai.ac.jp> (W32TeX).
+
2012-05-22 Taco Hoekwater <taco@luatex.org>
* lua/lkpselib.c: new function kpse.default_texmfcnf() that
diff --git a/Build/source/texk/web2c/luatexdir/lua/liolib.c b/Build/source/texk/web2c/luatexdir/lua/liolib.c
index a85b38b8683..b742928c6bd 100644
--- a/Build/source/texk/web2c/luatexdir/lua/liolib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/liolib.c
@@ -162,7 +162,7 @@ static int io_tostring(lua_State * L)
static int io_open(lua_State * L)
{
const char *filename = luaL_checkstring(L, 1);
- const char *mode = luaL_optstring(L, 2, "r");
+ const char *mode = luaL_optstring(L, 2, "rb");
FILE **pf = newfile(L);
*pf = fopen(filename, mode);
if (*pf == NULL)
@@ -178,7 +178,7 @@ static int io_open_ro(lua_State * L)
{
FILE **pf;
const char *filename = luaL_checkstring(L, 1);
- const char *mode = luaL_optstring(L, 2, "r");
+ const char *mode = luaL_optstring(L, 2, "rb");
if ((strcmp(mode, "r") != 0) && (strcmp(mode, "rb") != 0))
return pushresult(L, 0, filename);
pf = newfile(L);
@@ -200,7 +200,7 @@ static int io_popen(lua_State * L)
char *cmdname = NULL;
int allow = 0;
const char *cmd = luaL_checkstring(L, 1);
- const char *mode = luaL_optstring(L, 2, "r");
+ const char *mode = luaL_optstring(L, 2, "rb");
FILE **pf = newfile(L);
if (shellenabledp <= 0) {
@@ -212,7 +212,7 @@ static int io_popen(lua_State * L)
if (restrictedshell == 0)
allow = 1;
else
- allow = shell_cmd_is_allowed(&cmd, &safecmd, &cmdname);
+ allow = shell_cmd_is_allowed(cmd, &safecmd, &cmdname);
if (allow == 1) {
*pf = lua_popen(L, cmd, mode);
@@ -281,13 +281,13 @@ static int g_iofile(lua_State * L, int f, const char *mode)
static int io_input(lua_State * L)
{
- return g_iofile(L, IO_INPUT, "r");
+ return g_iofile(L, IO_INPUT, "rb");
}
static int io_output(lua_State * L)
{
- return g_iofile(L, IO_OUTPUT, "w");
+ return g_iofile(L, IO_OUTPUT, "wb");
}
@@ -319,7 +319,7 @@ static int io_lines(lua_State * L)
} else {
const char *filename = luaL_checkstring(L, 1);
FILE **pf = newfile(L);
- *pf = fopen(filename, "r");
+ *pf = fopen(filename, "rb");
if (*pf == NULL)
fileerror(L, 1, filename);
else
diff --git a/Build/source/texk/web2c/luatexdir/lua/loslibext.c b/Build/source/texk/web2c/luatexdir/lua/loslibext.c
index 8888d08a7cf..5bc46fca400 100644
--- a/Build/source/texk/web2c/luatexdir/lua/loslibext.c
+++ b/Build/source/texk/web2c/luatexdir/lua/loslibext.c
@@ -463,7 +463,7 @@ static int os_exec(lua_State * L)
allow = 1;
} else {
const char *theruncmd = runcmd;
- allow = shell_cmd_is_allowed(&theruncmd, &safecmd, &cmdname);
+ allow = shell_cmd_is_allowed(theruncmd, &safecmd, &cmdname);
}
if (allow > 0 && cmdline != NULL && runcmd != NULL) {
@@ -545,7 +545,7 @@ static int os_spawn(lua_State * L)
allow = 1;
} else {
const char *theruncmd = runcmd;
- allow = shell_cmd_is_allowed(&theruncmd, &safecmd, &cmdname);
+ allow = shell_cmd_is_allowed(theruncmd, &safecmd, &cmdname);
}
if (allow > 0 && cmdline != NULL && runcmd != NULL) {
if (allow == 2)
@@ -993,7 +993,7 @@ static int os_execute(lua_State * L)
if (restrictedshell == 0)
allow = 1;
else
- allow = shell_cmd_is_allowed(&cmd, &safecmd, &cmdname);
+ allow = shell_cmd_is_allowed(cmd, &safecmd, &cmdname);
if (allow == 1) {
lua_pushinteger(L, system(cmd));
diff --git a/Build/source/texk/web2c/luatexdir/luascripts/txt2zlib.w b/Build/source/texk/web2c/luatexdir/luascripts/txt2zlib.w
index ccf5d56cb88..f69d835673f 100644
--- a/Build/source/texk/web2c/luatexdir/luascripts/txt2zlib.w
+++ b/Build/source/texk/web2c/luatexdir/luascripts/txt2zlib.w
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "%s: can't open %s for reading.\n", argv[0], argv[1]);
exit(EXIT_FAILURE);
}
- fout = fopen(argv[2], "w");
+ fout = fopen(argv[2], "wb");
if (fout == NULL) {
fprintf(stderr, "%s: can't open %s for writing.\n", argv[0], argv[2]);
exit(EXIT_FAILURE);
diff --git a/Build/source/texk/web2c/luatexdir/luatex.c b/Build/source/texk/web2c/luatexdir/luatex.c
index 35da4e0e55c..814ee4d7f49 100644
--- a/Build/source/texk/web2c/luatexdir/luatex.c
+++ b/Build/source/texk/web2c/luatexdir/luatex.c
@@ -208,24 +208,24 @@ static int Isspace(char c)
should get executed. And we set CMDNAME to its first word; this is
what is checked against the shell_escape_commands list. */
-int shell_cmd_is_allowed(const char **cmd, char **safecmd, char **cmdname)
+int shell_cmd_is_allowed(const char *cmd, char **safecmd, char **cmdname)
{
char **p;
char *buf;
- char *s, *d;
- const char *ss;
+ char *c, *d;
+ const char *s;
int pre;
unsigned spaces;
int allow = 0;
/* pre == 1 means that the previous character is a white space
pre == 0 means that the previous character is not a white space */
- buf = (char *) xmalloc((unsigned) strlen(*cmd) + 1);
- strcpy(buf, *cmd);
- s = buf;
- while (Isspace(*s))
- s++;
- d = s;
+ buf = xmalloc(strlen(cmd) + 1);
+ strcpy(buf, cmd);
+ c = buf;
+ while (Isspace(*c))
+ c++;
+ d = c;
while (!Isspace(*d) && *d)
d++;
*d = '\0';
@@ -234,7 +234,7 @@ int shell_cmd_is_allowed(const char **cmd, char **safecmd, char **cmdname)
*cmdname == "kpsewhich" for
\write18{kpsewhich --progname=dvipdfm --format="other text files" config}
*/
- *cmdname = xstrdup(s);
+ *cmdname = xstrdup(c);
free(buf);
/* Is *cmdname listed in a texmf.cnf vriable as
@@ -253,37 +253,36 @@ int shell_cmd_is_allowed(const char **cmd, char **safecmd, char **cmdname)
}
if (allow == 2) {
spaces = 0;
- for (ss = *cmd; *ss; ss++) {
- if (Isspace(*ss))
+ for (s = cmd; *s; s++) {
+ if (Isspace(*s))
spaces++;
}
/* allocate enough memory (too much?) */
# ifdef WIN32
- *safecmd =
- (char *) xmalloc(2 * (unsigned) strlen(*cmd) + 3 + 2 * spaces);
+ *safecmd = xmalloc(2 * strlen(cmd) + 3 + 2 * spaces);
# else
- *safecmd = (char *) xmalloc((unsigned) strlen(*cmd) + 3 + 2 * spaces);
+ *safecmd = xmalloc(strlen(cmd) + 3 + 2 * spaces);
# endif
/* make a safe command line *safecmd */
- ss = *cmd;
- while (Isspace(*ss))
- ss++;
+ s = cmd;
+ while (Isspace(*s))
+ s++;
d = *safecmd;
- while (!Isspace(*ss) && *ss)
- *d++ = *ss++;
+ while (!Isspace(*s) && *s)
+ *d++ = *s++;
pre = 1;
- while (*ss) {
+ while (*s) {
/* Quotation given by a user. " should always be used; we
transform it below. On Unix, if ' is used, simply immediately
return a quotation error. */
- if (*ss == '\'') {
+ if (*s == '\'') {
return -1;
}
- if (*ss == '"') {
+ if (*s == '"') {
/* All arguments are quoted as 'foo' (Unix) or "foo" (Windows)
before calling system(). Therefore closing QUOTE is necessary
if the previous character is not a white space.
@@ -298,51 +297,51 @@ int shell_cmd_is_allowed(const char **cmd, char **safecmd, char **cmdname)
pre = 0;
/* output the quotation mark for the quoted argument */
*d++ = QUOTE;
- ss++;
+ s++;
- while (*ss != '"') {
+ while (*s != '"') {
/* Illegal use of ', or closing quotation mark is missing */
- if (*ss == '\'' || *ss == '\0')
+ if (*s == '\'' || *s == '\0')
return -1;
# ifdef WIN32
- if (char_needs_quote(*ss))
+ if (char_needs_quote(*s))
*d++ = '^';
# endif
- *d++ = *ss++;
+ *d++ = *s++;
}
/* Closing quotation mark will be output afterwards, so
we do nothing here */
- ss++;
+ s++;
/* The character after the closing quotation mark
should be a white space or NULL */
- if (!Isspace(*ss) && *ss)
+ if (!Isspace(*s) && *s)
return -1;
/* Beginning of a usual argument */
- } else if (pre == 1 && !Isspace(*ss)) {
+ } else if (pre == 1 && !Isspace(*s)) {
pre = 0;
*d++ = QUOTE;
# ifdef WIN32
- if (char_needs_quote(*ss))
+ if (char_needs_quote(*s))
*d++ = '^';
# endif
- *d++ = *ss++;
+ *d++ = *s++;
/* Ending of a usual argument */
- } else if (pre == 0 && Isspace(*ss)) {
+ } else if (pre == 0 && Isspace(*s)) {
pre = 1;
/* Closing quotation mark */
*d++ = QUOTE;
- *d++ = *ss++;
+ *d++ = *s++;
} else {
- /* Copy a character from *cmd to *safecmd. */
+ /* Copy a character from cmd to *safecmd. */
# ifdef WIN32
- if (char_needs_quote(*ss))
+ if (char_needs_quote(*s))
*d++ = '^';
# endif
- *d++ = *ss++;
+ *d++ = *s++;
}
}
/* End of the command line */
@@ -408,7 +407,7 @@ int runsystem(char *cmd)
allow = 1;
} else {
const char *thecmd = cmd;
- allow = shell_cmd_is_allowed(&thecmd, &safecmd, &cmdname);
+ allow = shell_cmd_is_allowed(thecmd, &safecmd, &cmdname);
}
if (allow == 1)
diff --git a/Build/source/texk/web2c/luatexdir/luatex.h b/Build/source/texk/web2c/luatexdir/luatex.h
index f10165aa8ee..db9c0961102 100644
--- a/Build/source/texk/web2c/luatexdir/luatex.h
+++ b/Build/source/texk/web2c/luatexdir/luatex.h
@@ -72,7 +72,7 @@
/* Executing shell commands. */
extern void mk_shellcmdlist(char *);
extern void init_shell_escape(void);
-extern int shell_cmd_is_allowed(const char **cmd, char **safecmd,
+extern int shell_cmd_is_allowed(const char *cmd, char **safecmd,
char **cmdname);
extern int runsystem(char *cmd);
diff --git a/Build/source/texk/web2c/luatexdir/tex/texfileio.w b/Build/source/texk/web2c/luatexdir/tex/texfileio.w
index 523b9e4f2ec..3d9afbe37e6 100644
--- a/Build/source/texk/web2c/luatexdir/tex/texfileio.w
+++ b/Build/source/texk/web2c/luatexdir/tex/texfileio.w
@@ -1125,20 +1125,38 @@ int readbinfile(FILE * f, unsigned char **tfm_buffer, int *tfm_size)
stderr, since we have nowhere better to use; and of course we return
a file handle (or NULL) instead of a status indicator.
+ Also, we append "b" to IO_MODE on Windows.
+
@c
-static FILE *runpopen(char *cmd, const char *mode)
+static FILE *runpopen(char *cmd, const char *io_mode)
{
FILE *f = NULL;
char *safecmd = NULL;
char *cmdname = NULL;
int allow;
+#ifndef WIN32
+ /* Use mode "r" or "w" for Posix. */
+ char mode[] = "X";
+#else
+ /* Use mode "rb" or "wb" for Windows. */
+ char mode[] = "Xb";
+ char *pp;
+
+ for (pp = cmd; *pp; pp++) {
+ if (*pp == '\'') *pp = '"';
+ }
+#endif
+
+ /* Replace 'X' by 'r' or 'w'. */
+ mode[0] = *io_mode;
+
/* If restrictedshell == 0, any command is allowed. */
if (restrictedshell == 0) {
allow = 1;
} else {
const char *thecmd = cmd;
- allow = shell_cmd_is_allowed(&thecmd, &safecmd, &cmdname);
+ allow = shell_cmd_is_allowed(thecmd, &safecmd, &cmdname);
}
if (allow == 1)
f = popen(cmd, mode);