mirror of
https://github.com/lunarmodules/luafilesystem.git
synced 2026-07-22 02:53:06 +00:00
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.
This commit is contained in:
@@ -827,7 +827,8 @@ static int _file_info_ (lua_State *L, int (*st)(const char*, STAT_STRUCT*)) {
|
|||||||
/* member not found */
|
/* member not found */
|
||||||
return luaL_error(L, "invalid attribute name '%s'", member);
|
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)) {
|
if (!lua_istable (L, 2)) {
|
||||||
lua_newtable (L);
|
lua_newtable (L);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -132,6 +132,17 @@ for key, value in pairs(attr) do
|
|||||||
"lfs.attributes values not consistent")
|
"lfs.attributes values not consistent")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Check that lfs.attributes accepts a table as second argument
|
||||||
|
local attr2 = {}
|
||||||
|
lfs.attributes(tmpfile, attr2)
|
||||||
|
for key, value in pairs(attr2) do
|
||||||
|
assert (value == lfs.attributes (tmpfile, key),
|
||||||
|
"lfs.attributes values with table argument not consistent")
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check that extra arguments are ignored
|
||||||
|
lfs.attributes(tmpfile, attr2, nil)
|
||||||
|
|
||||||
-- Remove new file and directory
|
-- Remove new file and directory
|
||||||
assert (os.remove (tmpfile), "could not remove new file")
|
assert (os.remove (tmpfile), "could not remove new file")
|
||||||
assert (lfs.rmdir (tmpdir), "could not remove new directory")
|
assert (lfs.rmdir (tmpdir), "could not remove new directory")
|
||||||
|
|||||||
Reference in New Issue
Block a user