mirror of
https://github.com/lua/lua
synced 2024-11-22 04:41:23 +03:00
Fixed bug: invalid mode can crash 'io.popen'
This commit is contained in:
parent
e7411fab80
commit
092f66fb05
2
liolib.c
2
liolib.c
@ -277,6 +277,8 @@ static int io_popen (lua_State *L) {
|
||||
const char *filename = luaL_checkstring(L, 1);
|
||||
const char *mode = luaL_optstring(L, 2, "r");
|
||||
LStream *p = newprefile(L);
|
||||
luaL_argcheck(L, ((mode[0] == 'r' || mode[0] == 'w') && mode[1] == '\0'),
|
||||
2, "invalid mode");
|
||||
p->f = l_popen(L, filename, mode);
|
||||
p->closef = &io_pclose;
|
||||
return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
|
||||
|
Loading…
Reference in New Issue
Block a user