Handle zero-length addresses in cmp_address().

Don't compare the data if there's none to compare.

Change-Id: Ib0e3541e448127869d19afddfc71bb441dba5874
Reviewed-on: https://code.wireshark.org/review/15840
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2016-06-11 19:13:14 -07:00
parent 24f02dafcd
commit 5416a34d57
1 changed files with 8 additions and 0 deletions

View File

@ -199,6 +199,14 @@ cmp_address(const address *addr1, const address *addr2) {
if (addr1->type < addr2->type) return -1;
if (addr1->len > addr2->len) return 1;
if (addr1->len < addr2->len) return -1;
if (addr1->len == 0) {
/*
* memcmp(NULL, NULL, 0) is *not* guaranteed to work, so
* if both addresses are zero-length, don't compare them
* (there's nothing to compare, so they're equal).
*/
return 0;
}
return memcmp(addr1->data, addr2->data, addr1->len);
}