From f8752d2ca3bdaa3162f681b5c6f7973c3e171171 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 15 Nov 2010 09:36:17 +0200 Subject: [PATCH] Basic protection against Lua os.exit() and posix.exec() (ticket #167) - Track posix.fork() and only allow exit() and exec() if the script has forked. There are other questionable items in posix extensions too but these are the worst offenders. - Using Lua registry for tracking forked status might be more Lua-way option but this'll do for now. --- luaext/lposix.c | 39 +++++++++++++++++++++++++++++++++++++-- luaext/lposix.h | 1 + rpmio/rpmlua.c | 1 + tests/rpmmacro.at | 13 +++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/luaext/lposix.c b/luaext/lposix.c index 5b26e0c..3b25157 100644 --- a/luaext/lposix.c +++ b/luaext/lposix.c @@ -42,6 +42,8 @@ #include "modemuncher.c" +static int have_forked = 0; + static const char *filetype(mode_t m) { if (S_ISREG(m)) return "regular"; @@ -323,7 +325,12 @@ static int Pexec(lua_State *L) /** exec(path,[args]) */ { const char *path = luaL_checkstring(L, 1); int i,n=lua_gettop(L); - char **argv = malloc((n+1)*sizeof(char*)); + char **argv; + + if (!have_forked) + return luaL_error(L, "exec not permitted in this context"); + + argv = malloc((n+1)*sizeof(char*)); if (argv==NULL) return luaL_error(L,"not enough memory"); argv[0] = (char*)path; for (i=1; i"]]:1: exit not permitted in this context] +) +AT_CLEANUP -- 2.7.4