From a066cd7bdcd0586fb59223a2cc56246c151c2070 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 22 Jan 2010 18:45:04 +0000 Subject: [PATCH] Add the missing dirname function to http-favicon.nse. I missed this when I copied parse_url_relative from favicon-survey.nse. Ron Meldau reported that this error is raised: http-favicon.nse:141: variable 'dirname' is not declared It happens when a web page specifies a relative icon URL in a link element. (dirname is used to absolutize the URL.) Also, I changed to code to be sure to pass a plain string and number for the host and port to parse_url_relative. Otherwise parse_url_relative may return the tables that it receives and complicate the matching code to decide if a URL should be followed. --- CHANGELOG | 6 ++++++ scripts/http-favicon.nse | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 9c89122aa..a89a42c2d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ # Nmap Changelog ($Id$); -*-text-*- +o Added a function that was missing from http-favicon.nse. Its absence + would cause the error + http-favicon.nse:141: variable 'dirname' is not declared + when a web page specified an relative icon URL through the link + element. This bug was reported by Ron Meldau. [David] + o Fixed an error that occurred when UDP scan was combined with version scan. UDP ports would appear in the state "unknown" at the end of the scan, and in some cases an assertion failure would be raised. diff --git a/scripts/http-favicon.nse b/scripts/http-favicon.nse index b7ea93896..6be7f6f4c 100644 --- a/scripts/http-favicon.nse +++ b/scripts/http-favicon.nse @@ -81,8 +81,9 @@ action = function(host, port) icon = parseIcon( index.body ) -- if we find a pattern if icon then + local hostname = host.targetname or (host.name ~= "" and host.name) or host.ip stdnse.print_debug(1, "Got icon URL %s.", icon) - local icon_host, icon_port, icon_path = parse_url_relative(icon, host, port, root) + local icon_host, icon_port, icon_path = parse_url_relative(icon, hostname, port.number, root) if (icon_host == host.ip or icon_host == host.targetname or icon_host == (host.name ~= '' and host.name)) and @@ -122,6 +123,12 @@ action = function(host, port) return result end +local function dirname(path) + local dir + dir = string.match(path, "^(.*)/") + return dir or "" +end + -- Return a URL's host, port, and path, filling in the results with the given -- host, port, and path if the URL is relative. Return nil if the scheme is not -- "http" or "https".