From: Tulio Magno Quites Machado Filho Date: Wed, 28 Dec 2016 13:38:56 +0000 (-0200) Subject: powerpc: Fix powerpc32/power7 memchr for large input sizes X-Git-Tag: glibc-2.25~133 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e628dd118807981bdd880731e6fdf019f64a245;p=thirdparty%2Fglibc.git powerpc: Fix powerpc32/power7 memchr for large input sizes The same error fixed in commit b224637928e9fc04e3cef3e10d02ccf042d01584 happens in the 32-bit implementation of memchr for power7. This patch adopts the same solution, with a minimal change: it implements a saturated addition where overflows sets the maximum pointer size to UINTPTR_MAX. --- diff --git a/ChangeLog b/ChangeLog index d9b2c981567..1ad68675c25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-12-28 Tulio Magno Quites Machado Filho + + * sysdeps/powerpc/powerpc32/power7/memchr.S (__memchr): Avoid an + overflow in pointer addition. + 2016-12-28 Rajalakshmi Srinivasaraghavan * sysdeps/powerpc/powerpc64/multiarch/Makefile diff --git a/sysdeps/powerpc/powerpc32/power7/memchr.S b/sysdeps/powerpc/powerpc32/power7/memchr.S index 318168b4cfa..5ce2bb0badd 100644 --- a/sysdeps/powerpc/powerpc32/power7/memchr.S +++ b/sysdeps/powerpc/powerpc32/power7/memchr.S @@ -26,7 +26,16 @@ ENTRY (__memchr) dcbt 0,r3 clrrwi r8,r3,2 insrwi r4,r4,8,16 /* Replicate byte to word. */ - add r7,r3,r5 /* Calculate the last acceptable address. */ + + /* Calculate the last acceptable address and check for possible + addition overflow by using satured math: + r7 = r3 + r5 + r7 |= -(r7 < x) */ + add r7,r3,r5 + subfc r6,r3,r7 + subfe r9,r9,r9 + or r7,r7,r9 + insrwi r4,r4,16,0 cmplwi r5,16 li r9, -1