diff --git a/libdnet-stripped/NMAP_MODIFICATIONS b/libdnet-stripped/NMAP_MODIFICATIONS index 5003ef0ef..9c5a4fc13 100644 --- a/libdnet-stripped/NMAP_MODIFICATIONS +++ b/libdnet-stripped/NMAP_MODIFICATIONS @@ -2318,3 +2318,20 @@ index 77225b6..baf02ce 100644 if (entry->intf_addr.addr_type == ADDR_TYPE_NONE) { /* Set primary address if unset. */ + +o Avoid buffer overrun from scanning 32 chars plus terminator into a 16-byte buffer. + +diff --git a/libdnet-stripped/src/intf.c b/libdnet-stripped/src/intf.c +index 315e7b0..6180d85 100644 +--- a/libdnet-stripped/src/intf.c ++++ b/libdnet-stripped/src/intf.c +@@ -776,7 +776,8 @@ _intf_get_aliases(intf_t *intf, struct intf_entry *entry) + if ((f = fopen(PROC_INET6_FILE, "r")) != NULL) { + while (ap < lap && + fgets(buf, sizeof(buf), f) != NULL) { +- sscanf(buf, "%04s%04s%04s%04s%04s%04s%04s%04s %x %02x %02x %02x %32s\n", ++ /* scan up to INTF_NAME_LEN-1 bytes to reserve space for null terminator */ ++ sscanf(buf, "%04s%04s%04s%04s%04s%04s%04s%04s %x %02x %02x %02x %15s\n", + s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], + &idx, &bits, &scope, &flags, name); + if (strcmp(name, entry->intf_name) == 0) { diff --git a/libdnet-stripped/src/intf.c b/libdnet-stripped/src/intf.c index 315e7b0bb..6180d8526 100644 --- a/libdnet-stripped/src/intf.c +++ b/libdnet-stripped/src/intf.c @@ -776,7 +776,8 @@ _intf_get_aliases(intf_t *intf, struct intf_entry *entry) if ((f = fopen(PROC_INET6_FILE, "r")) != NULL) { while (ap < lap && fgets(buf, sizeof(buf), f) != NULL) { - sscanf(buf, "%04s%04s%04s%04s%04s%04s%04s%04s %x %02x %02x %02x %32s\n", + /* scan up to INTF_NAME_LEN-1 bytes to reserve space for null terminator */ + sscanf(buf, "%04s%04s%04s%04s%04s%04s%04s%04s %x %02x %02x %02x %15s\n", s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], &idx, &bits, &scope, &flags, name); if (strcmp(name, entry->intf_name) == 0) {