]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
tile: Check for pointer add overflow in memchr
authorChris Metcalf <cmetcalf@mellanox.com>
Mon, 16 Jan 2017 20:38:25 +0000 (15:38 -0500)
committerChris Metcalf <cmetcalf@mellanox.com>
Mon, 16 Jan 2017 20:44:48 +0000 (15:44 -0500)
As was done in b224637928e9, check for large size causing an overflow
in the loop that walks over the array.

Branching out of line here is the fastest approach for handling this
problem, since tile can bundle the instructions to compute the branch
test in parallel with doing the required memchr loop setup computation.

Unfortunately, the existing saturated ops (e.g. tilegx addxsc) are
all signed saturing ops, so don't help with unsigned saturation.

ChangeLog
sysdeps/tile/tilegx/memchr.c
sysdeps/tile/tilepro/memchr.c

index 53883068060d9088e30c7dd31477161dbed34239..9498803f7fba461e72f233ffce302a9d3041785f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2017-01-16  Chris Metcalf  <cmetcalf@mellanox.com>
 
+       * sysdeps/tile/tilegx/memchr.c (__memchr): Handle pointer
+       wrap-around.
+       * sysdeps/tile/tilepro/memchr.c (__memchr): Likewise.
+
        * sysdeps/unix/sysv/linux/tile/ipc_priv.h: New file.
 
 2016-01-14  Siddhesh Poyarekar  <siddhesh@sourceware.org>
index 34df19d2319cb0ad6ad2fab30c2b41dff65ef897..7da0f79da2eea229378699c68fa88154bcd9736d 100644 (file)
@@ -51,6 +51,10 @@ __memchr (const void *s, int c, size_t n)
   /* Compute the address of the last byte. */
   last_byte_ptr = (const char *) s + n - 1;
 
+  /* Handle possible addition overflow.  */
+  if (__glibc_unlikely ((uintptr_t) last_byte_ptr < (uintptr_t) s))
+    last_byte_ptr = (const char *) UINTPTR_MAX;
+
   /* Compute the address of the word containing the last byte. */
   last_word_ptr = (const uint64_t *) ((uintptr_t) last_byte_ptr & -8);
 
index 1848a9cadb2db3960d05b5ee0e3d1a8762272fca..fba1f70c2cee5aa36b82ecf1683f8bebb388df38 100644 (file)
@@ -51,6 +51,10 @@ __memchr (const void *s, int c, size_t n)
   /* Compute the address of the last byte. */
   last_byte_ptr = (const char *) s + n - 1;
 
+  /* Handle possible addition overflow.  */
+  if (__glibc_unlikely ((uintptr_t) last_byte_ptr < (uintptr_t) s))
+    last_byte_ptr = (const char *) UINTPTR_MAX;
+
   /* Compute the address of the word containing the last byte. */
   last_word_ptr = (const uint32_t *) ((uintptr_t) last_byte_ptr & -4);