From 50919ed69ff64df51d8d586d00834fde3e901785 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Thu, 25 Aug 2016 18:24:57 +0300 Subject: Fix lfs.attributes and lfs.symlinkattributes extra argument handling When the second argument is not a string, _file_info() wants to ensure that there is a table on top of the stack: the second argument or a new table. If a new table is pushed it's created on top immediately, but if a table is passed as the second argument it can be followed by extra arguments, with the last one ending up being used as a table, causing a crash. The fix is to remove any potential extra arguments using `lua_settop(L, 2)`. Also added a few tests for this case. Ref #80. --- src/lfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lfs.c b/src/lfs.c index 93c1419..8154a46 100644 --- a/src/lfs.c +++ b/src/lfs.c @@ -827,7 +827,8 @@ static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) { /* member not found */ return luaL_error(L, "invalid attribute name '%s'", member); } - /* creates a table if none is given */ + /* creates a table if none is given, removes extra arguments */ + lua_settop(L, 2); if (!lua_istable (L, 2)) { lua_newtable (L); } -- cgit v1.2.3-55-g6feb