1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-15 20:29:03 +00:00

MongoDB wire protocol is using signed int32. Fixes #1802

Unlike the old bin library, Lua string.pack does not support silent conversions:
Negative integers cannot be "I" packed and 0xFFFFFFFF cannot be packed with "i4"
This commit is contained in:
nnposter
2019-11-17 03:05:30 +00:00
parent 45994bf3e4
commit 67fe6bb0fb
2 changed files with 13 additions and 10 deletions

View File

@@ -373,10 +373,10 @@ MongoData ={
return o
end
}
--Adds unsigned int32 to the message body
--Adds signed int32 to the message body
--@param value the value to add
function MongoData:addUnsignedInt32(value)
self.valueString = self.valueString..string.pack("<I4",value)
function MongoData:addInt32(value)
self.valueString = self.valueString..string.pack("<i4",value)
end
-- Adds a string to the message body
--@param value the string to add
@@ -402,10 +402,10 @@ end
-- This method creates necessary header information and puts it with the body
function MongoData:data()
local header = MongoData:new()
header:addUnsignedInt32( self.valueString:len()+4+4+4+4)
header:addUnsignedInt32( self.requestID)
header:addUnsignedInt32( self.responseTo or 0xFFFFFFFF)
header:addUnsignedInt32( self.opCode)
header:addInt32( self.valueString:len()+4+4+4+4)
header:addInt32( self.requestID)
header:addInt32( self.responseTo or -1)
header:addInt32( self.opCode)
return header.valueString .. self.valueString
end
-- Creates a query
@@ -415,10 +415,10 @@ end
--@return packet data OR error message
local function createQuery(collectionName, query)
local packet = MongoData:new({opCode=MongoData.OP.QUERY})
packet:addUnsignedInt32(0); -- options
packet:addInt32(0); -- options
packet:addString(collectionName);
packet:addUnsignedInt32(0) -- number to skip
packet:addUnsignedInt32(-1) -- number to return : no limit
packet:addInt32(0) -- number to skip
packet:addInt32(-1) -- number to return : no limit
local status, error = packet:addBSON(query)
if not status then