Skip to content

Commit

Permalink
Update mmhash.c
Browse files Browse the repository at this point in the history
Fix potential NULL ptr in as lookup
  • Loading branch information
phaag authored Jul 22, 2024
1 parent 0577dee commit 2fbc960
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/libnfdump/maxmind/mmhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,12 @@ uint32_t LookupV6AS(uint64_t ip[2]) {

const char *LookupASorg(uint32_t as) {
if (!mmHandle) {
return 0;
return NULL;
}

asOrgNode_t asSearch = {.as = as};
asOrgNode_t *asOrgNode = kb_getp(asOrgTree, mmHandle->asOrgTree, &asSearch);
return asOrgNode == NULL ? 0 : asOrgNode->orgName;
return asOrgNode == NULL ? "not found" : asOrgNode->orgName;

} // End of LookupASorg

Expand All @@ -480,7 +480,11 @@ void LookupAS(char *asString) {
if (as == 0 || as > 0xFFFFFFFFUL || as < 0) {
printf("Invalid AS number: %s: %s\n", asString, strerror(errno));
} else {
printf("%-7lu | %s\n", as, LookupASorg(as));
char *asOrg = LookupASorg(as);
if (asOrg == NULL)
printf("No DB available!\n");
else
printf("%-7lu | %s\n", as, LookupASorg(as));
}

} // End of LookupAS
Expand Down

0 comments on commit 2fbc960

Please sign in to comment.