Skip to content

Commit

Permalink
Set FD_CLOEXEC on opened files before exec from lua script is called
Browse files Browse the repository at this point in the history
rhbz:919801
  • Loading branch information
Lubos Kardos committed May 31, 2016
1 parent 816c7cf commit 7a7c31f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions luaext/lposix.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,22 @@ static int Pexec(lua_State *L) /** exec(path,[args]) */
const char *path = luaL_checkstring(L, 1);
int i,n=lua_gettop(L);
char **argv;
int flag, fdno, open_max;

if (!have_forked)
return luaL_error(L, "exec not permitted in this context");

open_max = sysconf(_SC_OPEN_MAX);
if (open_max == -1) {
open_max = 1024;
}
for (fdno = 3; fdno < open_max; fdno++) {
flag = fcntl(fdno, F_GETFD);
if (flag == -1 || (flag & FD_CLOEXEC))
continue;
fcntl(fdno, F_SETFD, FD_CLOEXEC);
}

argv = malloc((n+1)*sizeof(char*));
if (argv==NULL) return luaL_error(L,"not enough memory");
argv[0] = (char*)path;
Expand Down

0 comments on commit 7a7c31f

Please sign in to comment.