diff --git a/manual/luatex-lua.tex b/manual/luatex-lua.tex index 34a89b47396c9269a08f3a939f4cd1bebf457350..4e696572f46cf8640ebe7a3423dd6e72654d089e 100644 --- a/manual/luatex-lua.tex +++ b/manual/luatex-lua.tex @@ -503,10 +503,9 @@ that we will discuss here. \startitem \type {os.kpsepopen(commandline,[opt])} is similar to \type {io.popen} - but with a preliminary check of the command by mean of \type{kpse.check_permission}. - - If the command ran ok, then the return value is the same of \type{io.popen}; - otherwise it will return the two values \type {nil} and \type {error}. + but with a preliminary check of the commandline; + if the check is ok then the return value is the same as in \type{io.popen}; + Otherwise it will return the two values \type {nil} and \type {error}. \stopitem \startitem diff --git a/manual/luatex.pdf b/manual/luatex.pdf index 06b9cdf6411f9e9ff9339749221036671ee3a744..fa1a4ff74bbc0c748c8906b6a32515c9d8949222 100644 Binary files a/manual/luatex.pdf and b/manual/luatex.pdf differ diff --git a/source/texk/web2c/luatexdir/ChangeLog b/source/texk/web2c/luatexdir/ChangeLog index 06b6b2ebedaf43a0d85ed61ee5f9b9298042419e..5c257882b765be4c214cf610337bad2d279f4fcc 100644 --- a/source/texk/web2c/luatexdir/ChangeLog +++ b/source/texk/web2c/luatexdir/ChangeLog @@ -1,4 +1,8 @@ -2023-04-25 Luigi Scarso <luigi.scarso@gmail.com> +2023-04-24 Luigi Scarso <luigi.scarso@gmail.com> + * static kpse.check_permissions in os.kpsepopen + * Fixed date in ChangeLog + +2023-04-23 Luigi Scarso <luigi.scarso@gmail.com> * new os.kpsepopen -- replace io.popen if kpse is active. * Luatex 1.16.2 diff --git a/source/texk/web2c/luatexdir/lua/loslibext.c b/source/texk/web2c/luatexdir/lua/loslibext.c index d4c7984917e2c96b3c1032882e7c1e3a642a6554..909b17e13c00a6e070ce0897055e68066c906e64 100644 --- a/source/texk/web2c/luatexdir/lua/loslibext.c +++ b/source/texk/web2c/luatexdir/lua/loslibext.c @@ -1090,33 +1090,65 @@ static int io_kpse_pclose (lua_State *L) { LStream *p = tolstream(L); return luaL_execresult(L, l_kpse_pclose(L, p->f)); } +static int io_kpse_check_permissions(lua_State *L) { + const char *filename = luaL_checkstring(L, 1); + if (filename == NULL) { + lua_pushboolean(L,0); + lua_pushliteral(L,"no command name given"); + } else if (shellenabledp <= 0) { + lua_pushboolean(L,0); + lua_pushliteral(L,"all command execution is disabled"); + } else if (restrictedshell == 0) { + lua_pushboolean(L,1); + lua_pushstring(L,filename); + } else { + char *safecmd = NULL; + char *cmdname = NULL; + switch (shell_cmd_is_allowed(filename, &safecmd, &cmdname)) { + case 0: + lua_pushboolean(L,0); + lua_pushliteral(L, "specific command execution disabled"); + break; + case 1: + /* doesn't happen */ + lua_pushboolean(L,1); + lua_pushstring(L,filename); + break; + case 2: + lua_pushboolean(L,1); + lua_pushstring(L,safecmd); + break; + default: + /* -1 */ + lua_pushboolean(L,0); + lua_pushliteral(L, "bad command line quoting"); + break; + } + } + return 2; +} static int io_kpse_popen (lua_State *L) { const char *filename = NULL; const char *mode = NULL; LStream *p = NULL; + int okay; filename = luaL_checkstring(L, 1); mode = luaL_optstring(L, 2, "r"); - /* Check filename with kpse.check_permission . */ - lua_getglobal(L,"kpse"); - lua_getfield(L, -1, "check_permission"); lua_pushstring(L,filename); - if (lua_pcall(L,1,2,0)!=LUA_OK){ - return 1 ; + io_kpse_check_permissions(L); + filename = luaL_checkstring(L, -1); + okay = lua_toboolean(L,-2); + if (okay && filename) { + p = newprefile(L); + luaL_argcheck(L, ((mode[0] == 'r' || mode[0] == 'w') && mode[1] == '\0'), + 2, "invalid mode"); + p->f = l_kpse_popen(L, filename, mode); + p->closef = &io_kpse_pclose; + return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; } else { - filename = luaL_checkstring(L, -1); - int okay = lua_toboolean(L,-2); - if (okay && filename) { - p = newprefile(L); - luaL_argcheck(L, ((mode[0] == 'r' || mode[0] == 'w') && mode[1] == '\0'), - 2, "invalid mode"); - p->f = l_kpse_popen(L, filename, mode); - p->closef = &io_kpse_pclose; - return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; - } else { - lua_pushnil(L); - lua_pushvalue(L,-2); - return 2; - } + lua_pushnil(L); + lua_pushvalue(L,-2); + return 2; } } diff --git a/source/texk/web2c/luatexdir/luatex_svnversion.h b/source/texk/web2c/luatexdir/luatex_svnversion.h index 3f809ec866367efe82583c96e052b347e76664d9..09cdf66784ca2beb77a628d701db8ec7c0a71aa7 100644 --- a/source/texk/web2c/luatexdir/luatex_svnversion.h +++ b/source/texk/web2c/luatexdir/luatex_svnversion.h @@ -1,4 +1,4 @@ #ifndef luatex_svn_revision_h #define luatex_svn_revision_h -#define luatex_svn_revision 7575 +#define luatex_svn_revision 7576 #endif