]> git.puffer.fish Git - matthieu/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>
Wed, 15 Jan 2020 17:49:29 +0000 (12:49 -0500)
Very small (negative!) ifindexes, when subtracted, can overflow.

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

index f2746dad35723ac68f661433c452d08099bd72e8..c165ec5ea0c92df7282004c98f8e09e3a01f699c 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -130,7 +130,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;
 }
 
 /* Create new interface structure. */