From 9434dd7d2ff7e4fbe1eef82838d2eef3acaa0a95 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 7 Feb 2013 23:12:41 +0000 Subject: [PATCH] parse_redirect: fill in port number even if authority but not scheme is present. For example "//example.com/en/": the function needs to return with u.port set, just as it would with "http://example.com/en/". --- nselib/http.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/nselib/http.lua b/nselib/http.lua index bed57bb4a..d10730ea4 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -1407,22 +1407,23 @@ local function parse_redirect(host, port, path, response) end port = ( "number" == type(port) ) and { number = port } or port local u = url.parse(response.header.location) - if ( not(u.host) and not(u.scheme) ) then + if ( not(u.host) ) then -- we're dealing with a relative url - u.host, u.port = stdnse.get_hostname(host), port.number + u.host = stdnse.get_hostname(host) u.path = ((u.path:sub(1,1) == "/" and "" ) or "/" ) .. u.path -- ensuring leading slash end + -- do port fixup + if ( not(u.port) ) then + if ( u.scheme == "http" ) then u.port = 80 + elseif ( u.scheme == "https") then u.port = 443 + else u.port = port.number end + end if ( not(u.path) ) then u.path = "/" end if ( u.query ) then u.path = ("%s?%s"):format( u.path, u.query ) end - -- do port fixup - if ( not(u.port) ) then - if ( u.scheme == "http" ) then u.port = 80 end - if ( u.scheme == "https") then u.port = 443 end - end return u end