1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-21 15:09:02 +00:00

Check some libdnet mallocs for failure.

Patch based on one by Bill Parker.
http://seclists.org/nmap-dev/2012/q4/261
This commit is contained in:
david
2012-11-22 00:50:18 +00:00
parent f4ff002c71
commit f602ead419
3 changed files with 53 additions and 0 deletions

View File

@@ -1611,3 +1611,50 @@ index f12c8f7..ff86851 100644
} }
int int
o Add some checks for allocation functions returning NULL.
commit 5b8a67e968aff12df2bc3cf189b96c16eec6ae3f
Author: David Fifield <david@bamsoftware.com>
Date: Wed Nov 21 16:47:21 2012 -0800
Check some libdnet mallocs for failure.
Patch based on one by Bill Parker.
http://seclists.org/nmap-dev/2012/q4/261
diff --git a/libdnet-stripped/src/arp-win32.c b/libdnet-stripped/src/arp-win32.c
index 98b01c5..4434804 100644
--- a/libdnet-stripped/src/arp-win32.c
+++ b/libdnet-stripped/src/arp-win32.c
@@ -108,6 +108,8 @@ arp_loop(arp_t *arp, arp_handler callback, void *arg)
if (arp->iptable)
free(arp->iptable);
arp->iptable = malloc(len);
+ if (arp->iptable == NULL)
+ return (-1);
ret = GetIpNetTable(arp->iptable, &len, FALSE);
if (ret == NO_ERROR)
break;
diff --git a/libdnet-stripped/src/route-win32.c b/libdnet-stripped/src/route-win32.c
index ff86851..b4536b3 100644
--- a/libdnet-stripped/src/route-win32.c
+++ b/libdnet-stripped/src/route-win32.c
@@ -35,6 +35,8 @@ route_open(void)
route_t *r;
r = calloc(1, sizeof(route_t));
+ if (r == NULL)
+ return NULL;
r->iphlpapi = GetModuleHandle("iphlpapi.dll");
return r;
@@ -144,6 +146,8 @@ route_loop_getipforwardtable(route_t *r, route_handler callback, void *arg)
if (r->ipftable)
free(r->ipftable);
r->ipftable = malloc(len);
+ if (r->ipftable == NULL)
+ return (-1);
ret = GetIpForwardTable(r->ipftable, &len, FALSE);
if (ret == NO_ERROR)
break;

View File

@@ -108,6 +108,8 @@ arp_loop(arp_t *arp, arp_handler callback, void *arg)
if (arp->iptable) if (arp->iptable)
free(arp->iptable); free(arp->iptable);
arp->iptable = malloc(len); arp->iptable = malloc(len);
if (arp->iptable == NULL)
return (-1);
ret = GetIpNetTable(arp->iptable, &len, FALSE); ret = GetIpNetTable(arp->iptable, &len, FALSE);
if (ret == NO_ERROR) if (ret == NO_ERROR)
break; break;

View File

@@ -35,6 +35,8 @@ route_open(void)
route_t *r; route_t *r;
r = calloc(1, sizeof(route_t)); r = calloc(1, sizeof(route_t));
if (r == NULL)
return NULL;
r->iphlpapi = GetModuleHandle("iphlpapi.dll"); r->iphlpapi = GetModuleHandle("iphlpapi.dll");
return r; return r;
@@ -144,6 +146,8 @@ route_loop_getipforwardtable(route_t *r, route_handler callback, void *arg)
if (r->ipftable) if (r->ipftable)
free(r->ipftable); free(r->ipftable);
r->ipftable = malloc(len); r->ipftable = malloc(len);
if (r->ipftable == NULL)
return (-1);
ret = GetIpForwardTable(r->ipftable, &len, FALSE); ret = GetIpForwardTable(r->ipftable, &len, FALSE);
if (ret == NO_ERROR) if (ret == NO_ERROR)
break; break;