diff options
author | Thomas Haller <thaller@redhat.com> | 2019-08-27 12:43:54 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-08-27 12:46:21 (GMT) |
commit | 34708e2ef048f3788f3f2d5018735b27b156d244 (patch) | |
tree | 21b621aefb5e8d4e6d9aecdc2bfc905e11b48728 | |
parent | 194069516dcd16071314c110b18c3f325eac414f (diff) | |
download | libnl-34708e2ef048f3788f3f2d5018735b27b156d244.zip libnl-34708e2ef048f3788f3f2d5018735b27b156d244.tar.gz libnl-34708e2ef048f3788f3f2d5018735b27b156d244.tar.bz2 |
lib: accept %NULL arguments for nl_addr_cmp()
Just be more forgiving. Also, this avoids a coverity warning:
Error: FORWARD_NULL (CWE-476): [#def1]
libnl-3.4.0/lib/route/addr.c:502: var_compare_op: Comparing "a->a_peer" to null implies that "a->a_peer" might be null.
libnl-3.4.0/lib/route/addr.c:513: var_deref_model: Passing null pointer "a->a_peer" to "nl_addr_cmp", which dereferences it.
libnl-3.4.0/lib/addr.c:587:8: deref_parm: Directly dereferencing parameter "a".
# 585| int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b)
# 586| {
# 587|-> int d = a->a_family - b->a_family;
# 588|
# 589| if (d == 0) {
https://bugzilla.redhat.com/show_bug.cgi?id=1606988
-rw-r--r-- | lib/addr.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -585,8 +585,16 @@ int nl_addr_shared(const struct nl_addr *addr) */ int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b) { - int d = a->a_family - b->a_family; + int d; + + if (a == b) + return 0; + if (!a) + return -1; + if (!b) + return 1; + d = a->a_family - b->a_family; if (d == 0) { d = a->a_len - b->a_len; |