aboutsummaryrefslogtreecommitdiff
path: root/ld/emultempl
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-08-03 08:40:12 +0930
committerAlan Modra <amodra@gmail.com>2023-08-03 21:19:54 +0930
commiteaf1fa5ac5972efe5041c835c3ac9fec3c6aa06c (patch)
tree8534db6617357257593dabfdc483f8c819e0a47e /ld/emultempl
parent23f6f86ca03e87883150d21a6ac3c00590ea450a (diff)
downloadgdb-eaf1fa5ac5972efe5041c835c3ac9fec3c6aa06c.zip
gdb-eaf1fa5ac5972efe5041c835c3ac9fec3c6aa06c.tar.gz
gdb-eaf1fa5ac5972efe5041c835c3ac9fec3c6aa06c.tar.bz2
ld: sprintf sanitizer null destination pointer
* configure.ac (stpcpy): AC_CHECK_DECLS. * sysdep.h (stpcpy): Add fallback declaraion. * config.in: Regenerate. * configure: Regenerate. * emultempl/pe.em (open_dynamic_archive): Use stpcpy rather than sprintf plus strlen. * emultempl/pep.em (open_dynamic_archive): Likewise. * emultempl/xtensaelf.em (elf_xtensa_before_allocation): Use auto rather than malloc'd buffer. Use sprintf count. * ldelf.c (ldelf_search_needed): Use memcpy in place of sprintf. * pe-dll.c (pe_process_import_defs): Use string already formed for alias match rather than recreating.
Diffstat (limited to 'ld/emultempl')
-rw-r--r--ld/emultempl/pe.em4
-rw-r--r--ld/emultempl/pep.em4
-rw-r--r--ld/emultempl/xtensaelf.em10
3 files changed, 8 insertions, 10 deletions
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index cd2abe4..a583b02 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -2464,8 +2464,8 @@ gld${EMULATION_NAME}_open_dynamic_archive
search->name and the start of the format string. */
+ 2);
- sprintf (full_string, "%s/", search->name);
- base_string = full_string + strlen (full_string);
+ base_string = stpcpy (full_string, search->name);
+ *base_string++ = '/';
for (i = 0; libname_fmt[i].format; i++)
{
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index 28d8c8d..516d2af 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -2295,8 +2295,8 @@ gld${EMULATION_NAME}_open_dynamic_archive
search->name and the start of the format string. */
+ 2);
- sprintf (full_string, "%s/", search->name);
- base_string = full_string + strlen (full_string);
+ base_string = stpcpy (full_string, search->name);
+ *base_string++ = '/';
for (i = 0; libname_fmt[i].format; i++)
{
diff --git a/ld/emultempl/xtensaelf.em b/ld/emultempl/xtensaelf.em
index 4cb9bda..f2d10b5 100644
--- a/ld/emultempl/xtensaelf.em
+++ b/ld/emultempl/xtensaelf.em
@@ -490,15 +490,14 @@ elf_xtensa_before_allocation (void)
if (info_sec)
{
int xtensa_info_size;
- char *data;
+ char data[100];
info_sec->flags &= ~SEC_EXCLUDE;
info_sec->flags |= SEC_IN_MEMORY;
- data = xmalloc (100);
- sprintf (data, "USE_ABSOLUTE_LITERALS=%d\nABI=%d\n",
- XSHAL_USE_ABSOLUTE_LITERALS, xtensa_abi_choice ());
- xtensa_info_size = strlen (data) + 1;
+ xtensa_info_size
+ = 1 + sprintf (data, "USE_ABSOLUTE_LITERALS=%d\nABI=%d\n",
+ XSHAL_USE_ABSOLUTE_LITERALS, xtensa_abi_choice ());
/* Add enough null terminators to pad to a word boundary. */
do
@@ -512,7 +511,6 @@ elf_xtensa_before_allocation (void)
bfd_put_32 (info_sec->owner, XTINFO_TYPE, info_sec->contents + 8);
memcpy (info_sec->contents + 12, XTINFO_NAME, XTINFO_NAMESZ);
memcpy (info_sec->contents + 12 + XTINFO_NAMESZ, data, xtensa_info_size);
- free (data);
}
/* Enable relaxation by default if the "--no-relax" option was not