mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 09:49:05 +00:00
Change rpc's GetAdditionalBytes to error on a short read without an extra timeout
This commit is contained in:
@@ -287,8 +287,11 @@ Comm = {
|
|||||||
self.program_id = progid
|
self.program_id = progid
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- Checks if data contains enough bytes to read the <code>needed</code> amount
|
--- Checks if <code>data</code> contains enough bytes to read the <code>needed</code> amount
|
||||||
-- If it doesn't it attempts to read the remaining amount of bytes from the socket
|
--
|
||||||
|
-- If it doesn't it attempts to read the remaining amount of bytes from the
|
||||||
|
-- socket. Unlike <code>socket.receive_bytes</code>, reading less than
|
||||||
|
-- <code>needed</code> is treated as an error.
|
||||||
--
|
--
|
||||||
-- @param data string containing the current buffer
|
-- @param data string containing the current buffer
|
||||||
-- @param pos number containing the current offset into the buffer
|
-- @param pos number containing the current offset into the buffer
|
||||||
@@ -296,16 +299,19 @@ Comm = {
|
|||||||
-- @return status success or failure
|
-- @return status success or failure
|
||||||
-- @return data string containing the data passed to the function and the additional data appended to it or error message on failure
|
-- @return data string containing the data passed to the function and the additional data appended to it or error message on failure
|
||||||
GetAdditionalBytes = function( self, data, pos, needed )
|
GetAdditionalBytes = function( self, data, pos, needed )
|
||||||
local status, tmp
|
local toread = needed - ( data:len() - pos + 1 )
|
||||||
|
-- Do the loop ourselves instead of receive_bytes. Pathological case:
|
||||||
if data:len() - pos + 1 < needed then
|
-- * read less than needed and timeout
|
||||||
local toread = needed - ( data:len() - pos + 1 )
|
-- * receive_bytes returns short but we don't know if it's eof or timeout
|
||||||
status, tmp = self.socket:receive_bytes( toread )
|
-- * Try again. If it was timeout, we've doubled the timeout waiting for bytes that aren't coming.
|
||||||
|
while toread > 0 do
|
||||||
|
local status, tmp = self.socket:receive()
|
||||||
if status then
|
if status then
|
||||||
|
toread = toread - #tmp
|
||||||
data = data .. tmp
|
data = data .. tmp
|
||||||
else
|
else
|
||||||
return false, string.format("getAdditionalBytes() failed to read: %d bytes from the socket",
|
return false, string.format("getAdditionalBytes read %d bytes before error: %s",
|
||||||
needed - ( data:len() - pos ) )
|
needed - toread, tmp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true, data
|
return true, data
|
||||||
|
|||||||
Reference in New Issue
Block a user