mirror of
https://github.com/nmap/nmap.git
synced 2025-12-09 14:11:29 +00:00
Avoid __pairs metamethod in stdnse.keys
This allows stdnse.keys to be used in a __pairs metamethod to, for instance, yield keys in sorted order. Using next() bypasses the __pairs metamethod that would be called when pairs() was used. Otherwise, infinite recursion was possible.
This commit is contained in:
@@ -1416,8 +1416,10 @@ end
|
||||
-- @return A table of keys
|
||||
function keys(t)
|
||||
local ret = {}
|
||||
for k, _ in pairs(t) do
|
||||
local k, v = next(t)
|
||||
while k do
|
||||
ret[#ret+1] = k
|
||||
k, v = next(t, k)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user