Nmap Development mailing list archives

Revised Patches for NMAP-6.01


From: Bill Parker <wp02855 () gmail com>
Date: Wed, 21 Nov 2012 15:35:41 -0800

Hi All,

    Here are the revised patches for arp-win32.c, route-win32.c, and
nmap.cc that David Fifield request I modify
to bring them more inline with current NMAP development.

In arp-win32.c, I've called perror() rather than rely on fprintf(stderr,
<blah>);

--- arp-win32.c.orig 2012-11-11 13:21:39.610997814 -0800
+++ arp-win32.c 2012-11-21 12:50:54.397999406 -0800
@@ -108,6 +108,10 @@
  if (arp->iptable)
  free(arp->iptable);
  arp->iptable = malloc(len);
+ if (arp->iptable == NULL && len > 0) {
+ perror("Unable to allocate memory for arp->iptable in function
arp_loop...");
+ return (-1);
+ }
  ret = GetIpNetTable(arp->iptable, &len, FALSE);
  if (ret == NO_ERROR)
  break;
In route-win32.c, I've called perror() rather than rely on fprintf(stderr,
<blah>);

--- route-win32.c.orig 2012-11-11 13:35:15.231996335 -0800
+++ route-win32.c 2012-11-21 12:52:51.227001112 -0800
@@ -35,6 +35,10 @@
  route_t *r;

  r = calloc(1, sizeof(route_t));
+ if (r == NULL) {
+ perror("warning: unable to allocate memory in function route_open.");
+ return r;
+ }
  r->iphlpapi = GetModuleHandle("iphlpapi.dll");

  return r;
@@ -133,6 +137,10 @@
  if (r->ipftable)
  free(r->ipftable);
  r->ipftable = malloc(len);
+ if (r->ipftable == NULL && len > 0) {
+ perror("Unable to allocate memory for r->ipftable in function
route_loop...");
+ return (-1);
+ }
  ret = GetIpForwardTable(r->ipftable, &len, FALSE);
  if (ret == NO_ERROR)
  break;

and in nmap.cc, I changed the code to also print out strerror per david's
request:

--- nmap.cc.orig 2012-11-11 14:29:17.768998606 -0800
+++ nmap.cc 2012-11-21 14:48:07.069997940 -0800
@@ -2257,7 +2257,19 @@

   /* Ensure the log file ends with a newline */
   filestr[filelen - 1] = '\n';
-  munmap(filestr, filelen);
+
+  /*
+   * we cannot recover from a munmap() failure, but
+   * we can print out an informative message with
+   * the address location and size of the memory
+   * mapping which wasn't released by munmap().
+   */
+
+  if (munmap(filestr, filelen) != 0) {
+    error("Warning: unable to unmap memory at address %p and size %u.\n",
filestr, filelen);
+    error("value of 'errno' is: %s \n", strerror(errno));
+  }
+
   return 0;
 }

I have corrected the indentation and use of parens for return functions
where
appropriate to the file in question.  Please email me with any concerns or
issues.

I am attaching all three patch files to this email.

Bill Parker (wp02855 at gmail dot com)

Attachment: arp-win32.c.patch
Description:

Attachment: route-win32.c.patch
Description:

Attachment: nmap.cc.patch
Description:

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/

Current thread: