From a0a94f9303e499712bb9bf768adbd932404873bc Mon Sep 17 00:00:00 2001 From: dmiller Date: Thu, 26 Jun 2014 02:53:57 +0000 Subject: [PATCH] Properly handle interfaces with NULL addresses Some vsnprintf implementations (or perhaps some compiler options?) don't like formatting NULL as %s, and will segfault (ran into this with libstdc++ on Solaris). We don't get bug reports because at least some (including mine on Ubuntu) will simply format it as "(null)". This patch adds explicit checking for NULL to avoid the segfault condition. --- output.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/output.cc b/output.cc index d827c5ec6..08a651b07 100644 --- a/output.cc +++ b/output.cc @@ -364,6 +364,7 @@ int print_iflist(void) { struct sys_route *routes; NmapOutputTable *Tbl = NULL; char errstr[256]; + const char *address = NULL; errstr[0]='\0'; iflist = getinterfaces(&numifs, errstr, sizeof(errstr)); @@ -388,8 +389,10 @@ int print_iflist(void) { Tbl->addItem(i + 1, devcol, false, iflist[i].devfullname); Tbl->addItemFormatted(i + 1, shortdevcol, false, "(%s)", iflist[i].devname); + fprintf(stderr,"dev %s, AF %d\n", iflist[i].devname, iflist[i].addr.ss_family); + address = inet_ntop_ez(&(iflist[i].addr), sizeof(iflist[i].addr)); Tbl->addItemFormatted(i + 1, ipcol, false, "%s/%d", - inet_ntop_ez(&(iflist[i].addr), sizeof(iflist[i].addr)), + address == NULL ? "(none)" : address, iflist[i].netmask_bits); if (iflist[i].device_type == devt_ethernet) { Tbl->addItem(i + 1, typecol, false, "ethernet");