From bb9d03269cb9f8bca90596896dc36cbcf683ca51 Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 28 Jul 2016 18:51:40 +0000 Subject: [PATCH] Fix bin.pack('H') to allow whitespace, force crash on non-hex chars --- nselib/bin.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nselib/bin.lua b/nselib/bin.lua index 36d6608d3..3aaf2ca37 100644 --- a/nselib/bin.lua +++ b/nselib/bin.lua @@ -106,7 +106,7 @@ function _ENV.pack (format, ...) assert(n > 0, "n cannot be 0") -- original bin library allowed this, it doesn't make sense local new = "=" -- !! in original bin library, hex strings are always native for j = i, i+n-1 do - args[j] = tostring(args[j]):gsub("(%x%x?)", function (s) return char(tonumber(s, 16)) end) + args[j] = tostring(args[j]):gsub("%s*(%S%S?)%s*", function (s) return char(tonumber(s, 16)) end) new = new .. ("c%d"):format(#args[j]) end new = new .. endianness -- restore old endianness @@ -184,6 +184,7 @@ do -- !! endianness is always big endian for H !! assert(_ENV.pack(">H", "415D615A") == "\x41\x5D\x61\x5A") assert(_ENV.pack("