From d49a4a797514c019c7015f191c5f49e522d7a999 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Fri, 15 Jan 2016 15:02:00 +0000 Subject: [PATCH] Avoid overflow in compare_extable_entry() when entries are far appart Constrain the return value to strictly between -1 and 1. Without this, sorting extable entries which are further than 2GB apart fails, as the calculation overflows the return value. Signed-off-by: Andrew Cooper --- common/extable.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/extable.c b/common/extable.c index d5b47c9..b28dd78 100644 --- a/common/extable.c +++ b/common/extable.c @@ -33,7 +33,12 @@ static int compare_extable_entry(const void *_l, const void *_r) { const struct extable_entry *l = _l, *r = _r; - return l->fault - r->fault; + if ( l->fault == r->fault ) + return 0; + else if ( l->fault > r->fault ) + return 1; + else + return -1; } static void swap_extable_entry(void *_l, void *_r) -- 2.39.5