1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-08 23:49:03 +00:00

Lua 5.4 string.unpack() errors if no null in 'z' format

This commit is contained in:
dmiller
2023-05-01 17:44:40 +00:00
parent b8fd19c8d9
commit cd135ab3e8

View File

@@ -141,12 +141,12 @@ end
--@return the string
--@return the remaining data (*without* null-char)
local function get_c_string(data)
local value, pos = string.unpack("z", data)
if pos - #data > 1 then
local nullpos, nextpos = string.find(data, "\0")
if not nullpos then
dbg_err("C-string did not contain NULL char")
return nil, data
end
return value, data:sub(pos)
return data:sub(1, nullpos - 1), data:sub(nextpos + 1)
end
local function get_bson_str (data)