mirror of
https://github.com/nmap/nmap.git
synced 2026-10-09 05:44:36 +00:00
Fix removal (assignment to nil) of elements in stdnse.output_table.
There was a reverse table that was meant to map keys to their position in the order table, to make it easy to table.remove an entry from order. But removing something from order would shift the indices of all following elements by 1, and those elements were not updated correspondingly in the reverse table. Instead, do a linear lookup for the the element to remove from order, after checking that the element exists at all. http://seclists.org/nmap-dev/2012/q3/905
This commit is contained in:
parent
8f39b485a0
commit
cc126ea7d4
1 changed files with 11 additions and 12 deletions
|
|
@ -1122,7 +1122,6 @@ end
|
|||
-- @return An ordered table.
|
||||
function output_table ()
|
||||
local t = {}
|
||||
local reverse = {}
|
||||
local order = {}
|
||||
local function iterator ()
|
||||
for i, key in ipairs(order) do
|
||||
|
|
@ -1131,19 +1130,19 @@ function output_table ()
|
|||
end
|
||||
local mt = {
|
||||
__newindex = function (_, k, v)
|
||||
if reverse[k] then
|
||||
rawset(t, k, v)
|
||||
if v == nil then
|
||||
table.remove(order, reverse[k])
|
||||
reverse[k] = nil
|
||||
if t[k] == nil then
|
||||
-- New key?
|
||||
table.insert(order, k)
|
||||
elseif v == nil then
|
||||
-- Deleting an existing key?
|
||||
for i, key in ipairs(order) do
|
||||
if key == k then
|
||||
table.remove(order, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
if v ~= nil then
|
||||
table.insert(order, k)
|
||||
reverse[k] = #order
|
||||
end
|
||||
rawset(t, k, v)
|
||||
end
|
||||
rawset(t, k, v)
|
||||
end,
|
||||
__index = function (_, k)
|
||||
return t[k]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue