mirror of
https://github.com/nmap/nmap.git
synced 2025-12-24 00:19:01 +00:00
Optimize DALC structure marshalling in TNS
Avoids unnecessary splitting of the input string value
This commit is contained in:
@@ -1213,40 +1213,25 @@ Marshaller = {
|
|||||||
marshalKvpComponent = function( value )
|
marshalKvpComponent = function( value )
|
||||||
value = value or ""
|
value = value or ""
|
||||||
|
|
||||||
local result = {string.pack( "<I4", #value ),}
|
local sb4len = string.pack("<I4", #value)
|
||||||
if ( #value > 0 ) then
|
if #value == 0 then return sb4len end
|
||||||
-- 64 bytes seems to be the maximum length before Oracle starts
|
local result = {sb4len}
|
||||||
-- chunking strings
|
-- 64 bytes is the maximum before Oracle starts chunking strings
|
||||||
local MAX_CHUNK_LENGTH = 64
|
local MAX_CHUNK_LENGTH = 64
|
||||||
local split_into_chunks = ( #value > MAX_CHUNK_LENGTH )
|
if #value > MAX_CHUNK_LENGTH then
|
||||||
|
-- First, write the multiple-chunk indicator
|
||||||
if ( not( split_into_chunks ) ) then
|
table.insert(result, "\xFE")
|
||||||
-- It's pretty easy if we don't have to split up the string
|
-- Loop through the string value, chunk by chunk
|
||||||
result[#result+1] = string.pack( "s1", value )
|
local pos = 1
|
||||||
else
|
repeat
|
||||||
-- Otherwise, it's a bit more involved:
|
local nextpos = pos + MAX_CHUNK_LENGTH
|
||||||
-- First, write the multiple-chunk indicator
|
table.insert(result, string.pack("s1", value:sub(pos, nextpos - 1)))
|
||||||
result[#result+1] = "\xFE"
|
pos = nextpos
|
||||||
|
until pos > #value
|
||||||
-- Loop through the string, chunk by chunk
|
-- Finish with an empty chunk
|
||||||
while ( #value > 0 ) do
|
table.insert(result, "\0")
|
||||||
-- Figure out how much we're writing in this chunk, the
|
else
|
||||||
-- remainder of the string, or the maximum, whichever is less
|
table.insert(result, string.pack("s1", value))
|
||||||
local write_length = MAX_CHUNK_LENGTH
|
|
||||||
if (#value < MAX_CHUNK_LENGTH) then
|
|
||||||
write_length = #value
|
|
||||||
end
|
|
||||||
|
|
||||||
-- get a substring of what we're going to write...
|
|
||||||
local write_value = value:sub( 1, write_length )
|
|
||||||
-- ...and remove that piece from the remaining string
|
|
||||||
value = value:sub( write_length + 1 )
|
|
||||||
result[#result+1] = string.pack( "s1", write_value )
|
|
||||||
end
|
|
||||||
|
|
||||||
-- put a null byte at the end
|
|
||||||
result[#result+1] = '\0'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return table.concat(result)
|
return table.concat(result)
|
||||||
|
|||||||
Reference in New Issue
Block a user