This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATH] [BZ 15674] Fix reading past the array boundary in __memcmp_ssse3


On Wed, Jun 26, 2013 at 1:04 PM, Roland McGrath <roland@hack.frob.com> wrote:
>> +  int max_length = page_size / sizeof (CHAR);
>
> size_t.
>
>> +  CHAR * buf = (CHAR *) buf2;
>
> No space after *.
>
>> +  int length;
>> +
>> +  for (length = 1; length < max_length; length++)
>
> for (size_t length = ...
>
>> +    {
>> +      CHAR * s1 = (CHAR *) buf1 + max_length - length;
>> +      CHAR * s2 = (CHAR *) buf + max_length - length;
>
> No space after *.
>

Here is the new one.

--
H.J.
--
diff --git a/string/test-memcmp.c b/string/test-memcmp.c
index b30e34d..168fb79 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);
+
+  CHAR *buf = (CHAR *) buf2;
+  /* Initialize buf to the same values as buf1.  The bug requires the
+     last compared byte to be different.  */
+  memset (buf, 0xa5, page_size - 1);
+
+  for (size_t length = 1; length < max_length; length++)
+    {
+      CHAR *s1 = (CHAR *) buf1 + max_length - length;
+      CHAR *s2 = (CHAR *) buf + 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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]