From aed108fc8fdf22163b8ee6442ef93d0b0efa9741 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 26 Mar 2011 06:48:31 +0000 Subject: [PATCH] Add a same_file function and use it before warning about data files in the current directory, to avoid warnings like Warning: File ./nmap-services exists, but Nmap is using /home/david/nmap/nmap-services for security and consistency reasons. when . and /home/david/nmap are the same directory. --- nmap.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nmap.cc b/nmap.cc index 322e668c9..f10cd2e29 100644 --- a/nmap.cc +++ b/nmap.cc @@ -2714,6 +2714,19 @@ static char *executable_dir(const char *argv0) { return dir; } +/* Returns true if the two given filenames refer to the same file. (Have the + same device and inode number.) */ +static bool same_file(const char *filename_a, const char *filename_b) { + struct stat stat_a, stat_b; + + if (stat(filename_a, &stat_a) == -1) + return false; + if (stat(filename_b, &stat_b) == -1) + return false; + + return stat_a.st_dev == stat_b.st_dev && stat_a.st_ino == stat_b.st_ino; +} + int nmap_fetchfile(char *filename_returned, int bufferlen, const char *file) { char *dirptr; int res; @@ -2816,7 +2829,7 @@ int nmap_fetchfile(char *filename_returned, int bufferlen, const char *file) { if (foundsomething && (*filename_returned != '.')) { res = Snprintf(dot_buffer, sizeof(dot_buffer), "./%s", file); if (res > 0 && res < bufferlen) { - if (fileexistsandisreadable(dot_buffer)) { + if (fileexistsandisreadable(dot_buffer) && !same_file(filename_returned, dot_buffer)) { #ifdef WIN32 if (warningcount++ < 1 && o.debugging) #else