diff options
author | Alan Modra <amodra@gmail.com> | 2023-08-03 08:40:12 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-08-03 21:19:54 +0930 |
commit | eaf1fa5ac5972efe5041c835c3ac9fec3c6aa06c (patch) | |
tree | 8534db6617357257593dabfdc483f8c819e0a47e /ld/ldelf.c | |
parent | 23f6f86ca03e87883150d21a6ac3c00590ea450a (diff) | |
download | gdb-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/ldelf.c')
-rw-r--r-- | ld/ldelf.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -524,10 +524,13 @@ ldelf_search_needed (const char *path, struct dt_needed *n, int force, else { char * current_dir = getpwd (); - - freeme = xmalloc (strlen (replacement) - + strlen (current_dir) + 2); - sprintf (freeme, "%s/%s", current_dir, replacement); + size_t cdir_len = strlen (current_dir); + size_t rep_len = strlen (replacement); + freeme = xmalloc (cdir_len + rep_len + 2); + memcpy (freeme, current_dir, cdir_len); + freeme[cdir_len] = '/'; + memcpy (freeme + cdir_len + 1, + replacement, rep_len + 1); } replacement = freeme; |