]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ldelf_before_allocation leak
authorAlan Modra <amodra@gmail.com>
Mon, 20 Jan 2025 07:11:56 +0000 (17:41 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 20 Jan 2025 07:46:15 +0000 (18:16 +1030)
ldelf_before_allocation is passed the audit and depaudit strings built
from command line args, then possibly adds to the depaudit string,
freeing the original.  The new string isn't freed.  Fix this leak by
keeping the string attached to the static vars.

* ldelf.c (ldelf_before_allocation): Pass char** for audit
and depaudit.  Adjust uses.
* ldelf.h (ldelf_before_allocation): Update prototype.
* gld${EMULATION_NAME}_before_allocation: Update call.

ld/emultempl/elf.em
ld/ldelf.c
ld/ldelf.h

index 777f720403880a1a6f265143c7445a1004c8dd12..9dcb52e75148734da6be536b6447a6a4629d8e71 100644 (file)
@@ -170,7 +170,7 @@ fragment <<EOF
 static void
 gld${EMULATION_NAME}_before_allocation (void)
 {
-  ldelf_before_allocation (audit, depaudit, ${ELF_INTERPRETER_NAME});
+  ldelf_before_allocation (&audit, &depaudit, ${ELF_INTERPRETER_NAME});
 }
 
 EOF
index d627b55419b6e409a4389a60ce5e81ceb710e024..f56a62780f066220db4ffad8167c1380adc3fc40 100644 (file)
@@ -1752,7 +1752,7 @@ ldelf_append_to_separated_string (char **to, char *op_arg)
    sections, but before any sizes or addresses have been set.  */
 
 void
-ldelf_before_allocation (char *audit, char *depaudit,
+ldelf_before_allocation (char **audit, char **depaudit,
                         const char *default_interpreter_name)
 {
   const char *rpath;
@@ -1834,7 +1834,7 @@ ldelf_before_allocation (char *audit, char *depaudit,
                  }
 
                if (cp != NULL && *cp != '\0')
-                 ldelf_append_to_separated_string (&depaudit, cp);
+                 ldelf_append_to_separated_string (depaudit, cp);
 
                cp = more ? ++cp2 : NULL;
              }
@@ -1844,7 +1844,7 @@ ldelf_before_allocation (char *audit, char *depaudit,
 
   if (! (bfd_elf_size_dynamic_sections
         (link_info.output_bfd, command_line.soname, rpath,
-         command_line.filter_shlib, audit, depaudit,
+         command_line.filter_shlib, *audit, *depaudit,
          (const char * const *) command_line.auxiliary_filters,
          &link_info, &sinterp)))
     einfo (_("%F%P: failed to set dynamic section sizes: %E\n"));
index a6498cf27582050c7969b355a78e9bb965c3b543..e8b7c8c7eb896035cfbbc3c727f8d3b1a02f1862 100644 (file)
@@ -30,7 +30,7 @@ extern void ldelf_after_open (int, int, int, int, int, const char *);
 extern bool ldelf_setup_build_id (bfd *);
 extern bool ldelf_setup_package_metadata (bfd *);
 extern void ldelf_append_to_separated_string (char **, char *);
-extern void ldelf_before_allocation (char *, char *, const char *);
+extern void ldelf_before_allocation (char **, char **, const char *);
 extern bool ldelf_open_dynamic_archive
   (const char *, search_dirs_type *, lang_input_statement_type *);
 extern lang_output_section_statement_type *ldelf_place_orphan