]> xenbits.xensource.com Git - people/royger/xen-test-framework.git/commitdiff
Avoid overflow in compare_extable_entry() when entries are far appart
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 15 Jan 2016 15:02:00 +0000 (15:02 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 15 Jan 2016 15:02:00 +0000 (15:02 +0000)
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 <andrew.cooper3@citrix.com>
common/extable.c

index d5b47c952f1137b479620a7a73af38caca2835f0..b28dd78dc45b762100d8a67e74ea5bde9457be80 100644 (file)
@@ -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)