]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Replace `strcpy` call with `memcpy` [BZ #29454]
authorNoah Goldstein <goldstein.w.n@gmail.com>
Mon, 8 Aug 2022 03:26:22 +0000 (11:26 +0800)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Thu, 11 Aug 2022 14:11:14 +0000 (22:11 +0800)
GCC normally does this optimization for us in
strlen_pass::handle_builtin_strcpy but only for optimized
build. To avoid needing to include strcpy.S in the rtld build to
support the debug build, just do the optimization by hand.

(cherry picked from commit 483cfe1a6a33d6335b1901581b41040d2d412511)

elf/dl-cache.c

index 8bbf110d02c832df53924faf6b86a09df656c308..b97c17b3a9c5e750a673f6d1e3ed39022304652d 100644 (file)
@@ -509,8 +509,9 @@ _dl_load_cache_lookup (const char *name)
      we are accessing. Therefore we must make the copy of the
      mapping data without using malloc.  */
   char *temp;
-  temp = alloca (strlen (best) + 1);
-  strcpy (temp, best);
+  size_t best_len = strlen (best) + 1;
+  temp = alloca (best_len);
+  memcpy (temp, best, best_len);
   return __strdup (temp);
 }