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)