]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Add a test for BZ #15674
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 26 Jun 2013 22:23:08 +0000 (15:23 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 26 Jun 2013 22:23:08 +0000 (15:23 -0700)
ChangeLog
string/test-memcmp.c

index fd3a90f87a021dfd6dc48e0eb7a26a874e1d998d..37db6c0a1140b3f8ff8e034cfa17384482f608db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
 2013-06-26  Liubov Dmitrieva  <liubov.dmitrieva@intel.com>
 
        [BZ #15674]
+       * string/test-memcmp.c (check2): New.
+       (main): Call check2.
+
        * sysdeps/x86_64/multiarch/memcmp-ssse3.S: Fix buffers overrun.
 
 2013-06-26  Maciej W. Rozycki  <macro@codesourcery.com>
index b30e34d0e4340b858e634a690e34f3b7b419e6e3..0420cd0b7b62bf8bf7d99ec65d5f85745175bda3 100644 (file)
@@ -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)