]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
String: test-memcpy used unaligned types for buffers [BZ 28572]
authorJohn David Anglin <danglin@gcc.gnu.org>
Tue, 7 Dec 2021 22:10:20 +0000 (16:10 -0600)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Wed, 8 Dec 2021 04:19:50 +0000 (22:19 -0600)
commit d585ba47fcda99fdf228e3e45a01b11a15efbc5a
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Mon Nov 1 00:49:48 2021 -0500

    string: Make tests birdirectional test-memcpy.c

Add tests that had src/dst non 4-byte aligned. Since src/dst are
initialized/compared as uint32_t type which is 4-byte aligned this can
break on some targets.

Fix the issue by specifying a new non-aligned 4-byte
`unaligned_uint32_t` for src/dst.

Another alternative is to rely on memcpy/memcmp for
initializing/testing src/dst. Using memcpy for initializing in memcpy
tests, however, could lead to future bugs.

Reviewed-by: Noah Goldstein <goldstein.w.n@gmail.com>
string/test-memcpy-support.h

index 419158a4209d4a2b373aa84719f51cd066eaa952..b6cc434905754f9551ba1d6fcb14c716dba5e139 100644 (file)
@@ -51,6 +51,7 @@ builtin_memcpy (char *dst, const char *src, size_t n)
 }
 #endif
 typedef char *(*proto_t) (char *, const char *, size_t);
+typedef uint32_t __attribute__ ((may_alias, aligned (1))) unaligned_uint32_t;
 
 static void
 do_one_test (impl_t *impl, char *dst, const char *src, size_t len)
@@ -134,8 +135,8 @@ do_test1 (size_t align1, size_t align2, size_t size)
     error (EXIT_FAILURE, errno, "mprotect failed");
 
   size_t array_size = size / sizeof (uint32_t);
-  uint32_t *dest = large_buf + align1;
-  uint32_t *src = large_buf + region_size + 2 * page_size + align2;
+  unaligned_uint32_t *dest = large_buf + align1;
+  unaligned_uint32_t *src = large_buf + region_size + 2 * page_size + align2;
   size_t i;
   size_t repeats;
   for (repeats = 0; repeats < 2; repeats++)