public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* heap use after free in xcoff_archive_info_eq
@ 2020-09-03  1:37 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2020-09-03  1:37 UTC (permalink / raw)
  To: binutils

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.

diff --git a/bfd/xcofflink.c b/bfd/xcofflink.c
index 8870525472..ca7d7fec04 100644
--- a/bfd/xcofflink.c
+++ b/bfd/xcofflink.c
@@ -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;
 
diff --git a/ld/testsuite/ld-scripts/sysroot-prefix.exp b/ld/testsuite/ld-scripts/sysroot-prefix.exp
index e8b45d18e1..b7590e25a6 100644
--- a/ld/testsuite/ld-scripts/sysroot-prefix.exp
+++ b/ld/testsuite/ld-scripts/sysroot-prefix.exp
@@ -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"

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-03  1:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-03  1:37 heap use after free in xcoff_archive_info_eq Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).