From: Quentin Young Date: Sun, 5 Apr 2020 05:02:42 +0000 (-0400) Subject: bgpd: fix memcmp(null, *) when parsing bgp attrs X-Git-Tag: base_7.4~138^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=f22ed884c1c0ab1aeb8dec6e500a8e4934dbfbd3;p=matthieu%2Ffrr.git bgpd: fix memcmp(null, *) when parsing bgp attrs My first patch for this only fixed the memcmp(NULL, NULL) case. Signed-off-by: Quentin Young --- diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 221386e38d..8cb7a07f42 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -152,10 +152,16 @@ static bool cluster_hash_cmp(const void *p1, const void *p2) const struct cluster_list *cluster1 = p1; const struct cluster_list *cluster2 = p2; - return (cluster1->length == cluster2->length - && (cluster1->list == cluster2->list - || memcmp(cluster1->list, cluster2->list, cluster1->length) - == 0)); + if (cluster1->list == cluster2->list) + return true; + + if (!cluster1->list || !cluster2->list) + return false; + + if (cluster1->length != cluster2->length) + return false; + + return (memcmp(cluster1->list, cluster2->list, cluster1->length) == 0); } static void cluster_free(struct cluster_list *cluster)