about summary refs log tree commit diff
path: root/string/test-memcmp.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2013-06-26 15:23:08 -0700
committerH.J. Lu <hjl.tools@gmail.com>2013-06-26 15:23:08 -0700
commitbb5bb87cd2aa7462c88a11c69aa736ca62fd7cd8 (patch)
tree654302a42e27c7d8a20cf319bf2a97e0e66086bf /string/test-memcmp.c
parentfc74328c1f51955bd5f108485aad52bb9c2fa0d0 (diff)
downloadglibc-bb5bb87cd2aa7462c88a11c69aa736ca62fd7cd8.tar.gz
glibc-bb5bb87cd2aa7462c88a11c69aa736ca62fd7cd8.tar.xz
glibc-bb5bb87cd2aa7462c88a11c69aa736ca62fd7cd8.zip
Add a test for BZ #15674
Diffstat (limited to 'string/test-memcmp.c')
-rw-r--r--string/test-memcmp.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/string/test-memcmp.c b/string/test-memcmp.c
index b30e34d0e4..0420cd0b7b 100644
--- a/string/test-memcmp.c
+++ b/string/test-memcmp.c
@@ -448,6 +448,29 @@ check1 (void)
     }
 }
 
+/* This test checks that memcmp doesn't overrun buffers.  */
+static void
+check2 (void)
+{
+  size_t max_length = page_size / sizeof (CHAR);
+
+  /* Initialize buf2 to the same values as buf1.  The bug requires the
+     last compared byte to be different.  */
+  memcpy (buf2, buf1, page_size);
+  ((char *) buf2)[page_size - 1] ^= 0x11;
+
+  for (size_t length = 1; length < max_length; length++)
+    {
+      CHAR *s1 = (CHAR *) buf1 + max_length - length;
+      CHAR *s2 = (CHAR *) buf2 + max_length - length;
+
+      const int exp_result = SIMPLE_MEMCMP (s1, s2, length);
+
+      FOR_EACH_IMPL (impl, 0)
+	check_result (impl, s1, s2, length, exp_result);
+    }
+}
+
 int
 test_main (void)
 {
@@ -456,6 +479,7 @@ test_main (void)
   test_init ();
 
   check1 ();
+  check2 ();
 
   printf ("%23s", "");
   FOR_EACH_IMPL (impl, 0)