1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00

Fix the first round of HTTP pipeline requests. The pipeline makes an

initial request to get a value stored in the Keep-Alive header, which is
the size of the pipeline. It then iterates, doignt hat many requests at
once until the list of requests is exhausted. The prbolem was that in
the first round, it didn't count its initial Keep-Alive probe. So if the
server said it was good for 40 requests, we would send 41 before closing
the connection. Even worse was when the initial probe returned a
"Connection: close"; the pipeline would try another request before
closing the connection for the first time.
This commit is contained in:
david
2010-01-21 17:43:23 +00:00
parent c7b4af21db
commit 929042a690

View File

@@ -1141,21 +1141,21 @@ pipeline = function(host, port, allReqs)
responses[#responses + 1] = response
local limit = getPipelineMax(response)
local count = 1
stdnse.print_debug("Number of requests allowed by pipeline: " .. limit)
while #responses < #allReqs do
local j, batch_begin, batch_end
local j, batch_end
-- we build a big string with many requests, upper limited by the var "limit"
local requests = ""
batch_begin = #responses + 1
if #responses + limit < #allReqs then
batch_end = #responses + limit
else
batch_end = #allReqs
end
j = batch_begin
j = #responses + 1
while j <= batch_end do
if j == batch_end then
allReqs[j].opts.header["Connection"] = "close"
@@ -1165,9 +1165,10 @@ pipeline = function(host, port, allReqs)
end
-- Connect to host and send all the requests at once!
if not socket:get_info() then
if count >= limit or not socket:get_info() then
socket:connect(host.ip, port.number, bopt)
partial = ""
count = 0
end
socket:set_timeout(10000)
socket:send(requests)
@@ -1177,18 +1178,18 @@ pipeline = function(host, port, allReqs)
if not response then
break
end
count = count + 1
responses[#responses + 1] = response
end
socket:close()
partial = ""
if #responses + 1 == batch_begin then
if count == 0 then
stdnse.print_debug("Received 0 of %d expected reponses.\nGiving up on pipeline.", limit);
break
elseif #responses < batch_end then
stdnse.print_debug("Received only %d of %d expected reponses.\nDecreasing max pipelined requests to %d.", #responses + 1 - batch_begin, limit, #responses + 1 - batch_begin)
limit = #responses + 1 - batch_begin
elseif count < limit then
stdnse.print_debug("Received only %d of %d expected reponses.\nDecreasing max pipelined requests to %d.", count, limit, count)
limit = count
end
end