diff --git a/CHANGELOG b/CHANGELOG index 9b5fe9ed5..15daddee0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -88,6 +88,10 @@ o Fixed an issue where Nmap OS scan trusts a packet's ip_len to size a CRC32 computation over TCP RST payload data, which may result in reading arbitrary heap data. Reported by Michael Bommarito. +o [NSE] Fixed url.parse_query, which raised a Lua error on every call due to + passing the query string as the gsub pattern. Plus-to-space decoding is + restored. + o [Ncat][GH#3005] Correctly report listening port number. `ncat -l -p 0` will cause Ncat to listen on an ephemeral port, but it was reporting itself as listening on port 0. diff --git a/nselib/url.lua b/nselib/url.lua index 0b3530c62..1a5ff5f62 100644 --- a/nselib/url.lua +++ b/nselib/url.lua @@ -379,7 +379,7 @@ function parse_query(query) query = string.gsub(query, "&([ampltg]+);", entities) local parsed = {} - for qseg in query:gsub(query, "%+", " "):gmatch("[^&]+") do + for qseg in query:gsub("%+", " "):gmatch("[^&]+") do local k, v = qseg:match("^([^=]*)=?(.*)") parsed[unescape(k)] = unescape(v) end @@ -512,6 +512,21 @@ for _, t in ipairs(test_urls) do test_suite:add_test(unittest.equal(build(result), t._url), "parse/build round trip") end +-- parse_query tests. {query, expected name/value table} +local parse_query_tests = { + {"foo=1&bar=2", {foo = "1", bar = "2"}}, + {"a+b=c+d", {["a b"] = "c d"}}, + {"a%20b=c%26d", {["a b"] = "c&d"}}, + } +for k, v in ipairs(parse_query_tests) do + local query, expected = table.unpack(v) + local result = parse_query(query) + for name, value in pairs(expected) do + test_suite:add_test(unittest.equal(result[name], value), + ("parse_query #%d (%q) %q"):format(k, query, name)) + end +end + -- path merging tests for compliance with RFC 3986, section 5.2 -- https://tools.ietf.org/html/rfc3986#section-5.2