From cd135ab3e819bf2fb2a1073186ffb8160200ad3a Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 1 May 2023 17:44:40 +0000 Subject: [PATCH] Lua 5.4 string.unpack() errors if no null in 'z' format --- nselib/mongodb.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nselib/mongodb.lua b/nselib/mongodb.lua index a3277690a..59eb56470 100644 --- a/nselib/mongodb.lua +++ b/nselib/mongodb.lua @@ -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)