diff options
Diffstat (limited to 'libs/liblua/src/liolib.c')
-rw-r--r-- | libs/liblua/src/liolib.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libs/liblua/src/liolib.c b/libs/liblua/src/liolib.c index 7ac3444393..60ab1bfab6 100644 --- a/libs/liblua/src/liolib.c +++ b/libs/liblua/src/liolib.c @@ -52,6 +52,12 @@ static int l_checkmode (const char *mode) { ** ======================================================= */ +#if !defined(l_checkmodep) +/* By default, Lua accepts only "r" or "w" as mode */ +#define l_checkmodep(m) ((m[0] == 'r' || m[0] == 'w') && m[1] == '\0') +#endif + + #if !defined(l_popen) /* { */ #if defined(LUA_USE_POSIX) /* { */ @@ -279,6 +285,7 @@ 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, l_checkmodep(mode), 2, "invalid mode"); p->f = l_popen(L, filename, mode); p->closef = &io_pclose; return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1; |