]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: fix ifindex comparison overflow
authorQuentin Young <qlyoung@cumulusnetworks.com>
Sat, 4 Jan 2020 00:25:38 +0000 (19:25 -0500)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Sat, 4 Jan 2020 00:25:38 +0000 (19:25 -0500)
Very small (negative!) ifindexes, when subtracted, can overflow.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/if.c

index c91407084e039561de6d167a100e6a178d80cba1..7332dceb45e89bf7d336a18029ae073349072108 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -137,7 +137,12 @@ static int if_cmp_func(const struct interface *ifp1,
 static int if_cmp_index_func(const struct interface *ifp1,
                             const struct interface *ifp2)
 {
-       return ifp1->ifindex - ifp2->ifindex;
+       if (ifp1->ifindex == ifp2->ifindex)
+               return 0;
+       else if (ifp1->ifindex > ifp2->ifindex)
+               return 1;
+       else
+               return -1;
 }
 
 static void ifp_connected_free(void *arg)