From: Mark Wielaard Date: Tue, 16 Dec 2014 10:04:55 +0000 (+0100) Subject: elfcmp: Make sure Elf32_Word difference doesn't wrap around in int compare. X-Git-Tag: elfutils-0.161~29 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=274cbda6f5d5b7c57d488edaeb55876ba8705db3;p=thirdparty%2Felfutils.git elfcmp: Make sure Elf32_Word difference doesn't wrap around in int compare. Signed-off-by: Mark Wielaard --- diff --git a/src/ChangeLog b/src/ChangeLog index 141b31f05..1e612bf64 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2014-12-16 Mark Wielaard + + * elfcmp.c (compare_Elf32_Word): Make sure (unsigned) Elf32_Word + difference doesn't wrap around before returning as int. + 2014-12-11 Mark Wielaard * readelf.c (print_debug_exception_table): Check TType base offset diff --git a/src/elfcmp.c b/src/elfcmp.c index c420019f5..d1008b3c3 100644 --- a/src/elfcmp.c +++ b/src/elfcmp.c @@ -811,8 +811,7 @@ compare_Elf32_Word (const void *p1, const void *p2) { const Elf32_Word *w1 = p1; const Elf32_Word *w2 = p2; - assert (sizeof (int) >= sizeof (*w1)); - return (int) *w1 - (int) *w2; + return *w1 < *w2 ? -1 : *w1 > *w2 ? 1 : 0; } static int