Fix potentially undefined behaviour use of strcpcy.
authorNick Clifton <nickc@redhat.com>
Tue, 16 Mar 2021 14:02:38 +0000 (14:02 +0000)
committerNick Clifton <nickc@redhat.com>
Tue, 16 Mar 2021 14:02:59 +0000 (14:02 +0000)
* pe-dll.c (pe_find_cdecl_alias_match): Use memmove to overwrite
lname string.

ld/ChangeLog
ld/pe-dll.c

index 01b93c52cb97dd52d3560907b53a7f2f386236ea..7cc917a5128da686e28bfbf300c96be2c6917e43 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-16  Nick Clifton  <nickc@redhat.com>
+
+       * pe-dll.c (pe_find_cdecl_alias_match): Use memmove to overwrite
+       lname string.
+
 2021-03-15  Jan Beulich  <jbeulich@suse.com>
 
        * pe-dll.c (generate_reloc): Drop padding to reloc_s->size.
index eaecb951efdfc04b63a0b83fe913860d1c4e37bc..7aba09cd3596631e10b8f8bd85c195480dbbbb50 100644 (file)
@@ -3039,7 +3039,9 @@ pe_find_cdecl_alias_match (struct bfd_link_info *linfo, char *name)
          if (pe_details->underscored)
            lname[0] = '_';
          else
-           strcpy (lname, lname + 1);
+           /* Use memmove rather than strcpy as that
+              can handle overlapping buffers.  */
+           memmove (lname, lname + 1, strlen (lname));
          key.key = lname;
          kv = bsearch (&key, udef_table, undef_count,
                        sizeof (struct key_value), undef_sort_cmp);