summaryrefslogtreecommitdiff
path: root/libctf/ctf-archive.c
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2020-06-09 10:27:57 +0100
committerNick Alcock <nick.alcock@oracle.com>2020-07-22 18:02:18 +0100
commitd50c08025d41b2efc70dbb384fc691f2d9632463 (patch)
treef32f5a1ea26d5cedd9d159135ea48a16aa3f4d94 /libctf/ctf-archive.c
parent70447401740235d828c4b7b87e398eeae4801094 (diff)
downloadbinutils-gdb-d50c08025d41b2efc70dbb384fc691f2d9632463.tar.gz
libctf, open: fix opening CTF in binaries with no symtab
This is a perfectly possible case, and half of ctf_bfdopen_ctfsect handled it fine. The other half hit a divide by zero or two before we got that far, and had no code path to load the strtab from anywhere in the absence of a symtab to point at it in any case. So, as a fallback, if there is no symtab, try loading ".strtab" explicitly by name, like we used to before we started looking for the strtab the symtab used. Of course, such a strtab is not kept hold of by BFD, so this means we have to bring back the code to possibly explicitly free the strtab that we read in. libctf/ * ctf-impl.h (struct ctf_archive_internal) <ctfi_free_strsect> New. * ctf-open-bfd.c (ctf_bfdopen_ctfsect): Explicitly open a strtab if the input has no symtab, rather than dividing by zero. Arrange to free it later via ctfi_free_ctfsect. * ctf-archive.c (ctf_new_archive_internal): Do not ctfi_free_strsect by default. (ctf_arc_close): Possibly free it here.
Diffstat (limited to 'libctf/ctf-archive.c')
-rw-r--r--libctf/ctf-archive.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/libctf/ctf-archive.c b/libctf/ctf-archive.c
index 54d3d0a48f8..e33f1cc9eaf 100644
--- a/libctf/ctf-archive.c
+++ b/libctf/ctf-archive.c
@@ -368,6 +368,7 @@ ctf_new_archive_internal (int is_archive, int unmap_on_close,
if (strsect)
memcpy (&arci->ctfi_strsect, strsect, sizeof (struct ctf_sect));
arci->ctfi_free_symsect = 0;
+ arci->ctfi_free_strsect = 0;
arci->ctfi_unmap_on_close = unmap_on_close;
return arci;
@@ -493,6 +494,8 @@ ctf_arc_close (ctf_archive_t *arc)
ctf_file_close (arc->ctfi_file);
if (arc->ctfi_free_symsect)
free ((void *) arc->ctfi_symsect.cts_data);
+ if (arc->ctfi_free_strsect)
+ free ((void *) arc->ctfi_strsect.cts_data);
free (arc->ctfi_data);
if (arc->ctfi_bfd_close)
arc->ctfi_bfd_close (arc);