heap use after free in xcoff_archive_info_eq
authorAlan Modra <amodra@gmail.com>
Thu, 3 Sep 2020 00:04:37 +0000 (09:34 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 3 Sep 2020 01:34:46 +0000 (11:04 +0930)
Using an input file objalloc memory for anything that isn't created
when opening the bfd is not a good idea.  The problem is that this
memory can disappear if bfd_free_cached_info is called or when bfd
closes files in order to keep the number of open files reasonable.

bfd/
* xcofflink.c (xcoff_get_archive_info): Allocate xcoff_archive_info
on the output bfd objalloc memory.
ld/
* testsuite/ld-scripts/sysroot-prefix.exp (single_sysroot_prefix_test):
Log $scriptname.

bfd/ChangeLog
bfd/xcofflink.c
ld/ChangeLog
ld/testsuite/ld-scripts/sysroot-prefix.exp

index 156bb7abf739c3d66b4ee2eaf09b241e6296d574..76055ba18f2a3f5c6d9676ad635ccab9a30be94d 100644 (file)
@@ -1,3 +1,8 @@
+2020-09-03  Alan Modra  <amodra@gmail.com>
+
+       * xcofflink.c (xcoff_get_archive_info): Allocate xcoff_archive_info
+       on the output bfd objalloc memory.
+
 2020-09-02  Alan Modra  <amodra@gmail.com>
 
        * elfnn-aarch64.c (elfNN_aarch64_relocate_section): Correct type
index 887052547219ce01b2f6c81bdaafecf52ddae1cf..ca7d7fec04bba08cf2a6bb6056511a0467121e4a 100644 (file)
@@ -525,7 +525,7 @@ xcoff_get_archive_info (struct bfd_link_info *info, bfd *archive)
   entryp = *slot;
   if (!entryp)
     {
-      entryp = bfd_zalloc (archive, sizeof (entry));
+      entryp = bfd_zalloc (info->output_bfd, sizeof (entry));
       if (!entryp)
        return NULL;
 
index 0138e88db0adb99eabe2f9b251f337851d2023d1..6c447dd4af07246fde6cf5829d15d17ebf0cbc96 100644 (file)
@@ -1,3 +1,8 @@
+2020-09-03  Alan Modra  <amodra@gmail.com>
+
+       * testsuite/ld-scripts/sysroot-prefix.exp (single_sysroot_prefix_test):
+       Log $scriptname.
+
 2020-08-30  H.J. Lu  <hongjiu.lu@intel.com>
 
        * testsuite/ld-elf/dwarf.exp: Append $NOSANTIZE_CFLAGS to CFLAGS.
index e8b45d18e107a9a5092e6a17aa66b26dec26722b..b7590e25a648f05df05d24b00cfb4602d15627ae 100644 (file)
@@ -164,7 +164,7 @@ proc single_sysroot_prefix_test { type xtestname finalscript ldopt errstr } {
 
     puts $ofd "$finalscript"
     close $ofd
-    verbose -log "script: $finalscript"
+    verbose -log "script $scriptname: $finalscript"
 
     set res [ld_link $ld tmpdir/output "$ldopt tmpdir/main.o -Ltmpdir -lsysroottest"]
     set ld_output "$exec_output"