From d50c08025d41b2efc70dbb384fc691f2d9632463 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Tue, 9 Jun 2020 10:27:57 +0100 Subject: 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) 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. --- libctf/ctf-impl.h | 1 + 1 file changed, 1 insertion(+) (limited to 'libctf/ctf-impl.h') diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index 47a3927..913a264 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -333,6 +333,7 @@ struct ctf_archive_internal ctf_sect_t ctfi_symsect; ctf_sect_t ctfi_strsect; int ctfi_free_symsect; + int ctfi_free_strsect; void *ctfi_data; bfd *ctfi_abfd; /* Optional source of section data. */ void (*ctfi_bfd_close) (struct ctf_archive_internal *); -- cgit v1.1