From 5f5c8b32f69000a61a9c9a50cd80a9c96f8884b4 Mon Sep 17 00:00:00 2001 From: nnposter Date: Sat, 20 Jul 2019 23:37:32 +0000 Subject: [PATCH] Add support for gzip-encoded, yet empty body. Closes #1662 --- nselib/http.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nselib/http.lua b/nselib/http.lua index e0053d481..e8b09dde8 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -863,6 +863,7 @@ local decode_body = function (body, encodings, maxlen) ("Corrupted Content-Encoding: " .. enc), body end table.insert(decoded, table.remove(undecoded, 1)) + newbody = newbody or "" if maxlen and #newbody > maxlen then return nil, decoded, undecoded, ERR_OVERSIZED_BODY, newbody:sub(1, maxlen) end @@ -3143,6 +3144,15 @@ do undecoded = {}, maxlen = 13 }) + table.insert(content_encoding_tests, + { name = "gzip-encoded empty body", + encoding = "gzip", + source = "", + target = "", + decoded = {"gzip"}, + undecoded = {}, + maxlen = 999 + }) end table.insert(content_encoding_tests, { name = "unknown encoding", @@ -3168,7 +3178,7 @@ do source = stdnse.fromhex("1f8b0800000000000000f348cdc9c9d75108cf2fca49510400d0c34aec0d000000"), target = stdnse.fromhex("1f8b0800000000000000f348cdc9c9d75108cf2fca49510400d0c34aec0d000000"), decoded = {"identity"}, - undecoded = {"gzip", "identity"}, + undecoded = {"gzip", "identity"} }) end for _, test in ipairs(content_encoding_tests) do