From fdaa21d5fc4e8526b432f5c4d664f9139a97422b Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Fri, 3 Jan 2020 19:25:38 -0500 Subject: [PATCH] lib: fix ifindex comparison overflow Very small (negative!) ifindexes, when subtracted, can overflow. Signed-off-by: Quentin Young --- lib/if.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/if.c b/lib/if.c index f2746dad35..c165ec5ea0 100644 --- 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. */ -- 2.39.5