From 87274f81fcdf5005dd258100ce02bdb69786b3ed Mon Sep 17 00:00:00 2001 From: dmiller Date: Fri, 4 Nov 2022 22:07:28 +0000 Subject: [PATCH] Handle blank lines and duplicate protocol numbers. Fixes #2558 --- protocols.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/protocols.cc b/protocols.cc index 247353988..f759ad340 100644 --- a/protocols.cc +++ b/protocols.cc @@ -117,7 +117,7 @@ static int nmap_protocols_init() { p = line; while(*p && isspace((int) (unsigned char) *p)) p++; - if (*p == '#') + if (*p == '#' || *p == '\0') continue; res = sscanf(line, "%127s %hu", protocolname, &protno); if (res !=2 || protno > UCHAR_MAX) { @@ -134,12 +134,18 @@ static int nmap_protocols_init() { /* Now we make sure our protocols don't have duplicates */ if (!status.second) { if (o.debugging > 1) { - error("Protocol %d is duplicated in protocols file %s", protno, filename); + error("Protocol %d (%s) has duplicate number (%d) in protocols file %s", status.first->second.p_proto, ent.p_name, protno, filename); + } + continue; + } + + if (protocol_table[protno]) { + if (o.debugging > 1) { + error("Protocol %d (%s) has duplicate name (%s) in protocols file %s", protno, protocol_table[protno]->p_name, ent.p_name, filename); } continue; } - assert(!protocol_table[protno]); protocol_table[protno] = &status.first->second; } fclose(fp);