From 379759d539f61cfbf89e9ad7f78e4d8b0b82badc Mon Sep 17 00:00:00 2001 From: dmiller Date: Tue, 23 Sep 2014 05:23:06 +0000 Subject: [PATCH] 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. --- nselib/stdnse.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nselib/stdnse.lua b/nselib/stdnse.lua index 6e586595b..c4e146380 100644 --- a/nselib/stdnse.lua +++ b/nselib/stdnse.lua @@ -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