diff options
author | Alan Modra <amodra@gmail.com> | 2023-03-14 10:11:58 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-03-14 12:19:09 +1030 |
commit | 746598e07f7b666872bc31471de1b72de8a69c2b (patch) | |
tree | 7b2828b2a7bf0da59ddbbeed57c2772dd51dbd10 /binutils | |
parent | f049c18961236c3bf91409a060c1c9a709b96b44 (diff) | |
download | gdb-746598e07f7b666872bc31471de1b72de8a69c2b.zip gdb-746598e07f7b666872bc31471de1b72de8a69c2b.tar.gz gdb-746598e07f7b666872bc31471de1b72de8a69c2b.tar.bz2 |
Sanity check read_section_stabs_debugging_info
* rddbg.c (read_section_stabs_debugging_info): Exclude sections
without contents. Use bfd_malloc_and_get_section. Don't alloc
one extra for strings.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/rddbg.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/binutils/rddbg.c b/binutils/rddbg.c index 036a74f..f2ed6bc 100644 --- a/binutils/rddbg.c +++ b/binutils/rddbg.c @@ -117,39 +117,37 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount, sec = bfd_get_section_by_name (abfd, names[i].secname); strsec = bfd_get_section_by_name (abfd, names[i].strsecname); - if (sec != NULL && strsec != NULL) + if (sec != NULL + && (bfd_section_flags (sec) & SEC_HAS_CONTENTS) != 0 + && strsec != NULL + && (bfd_section_flags (strsec) & SEC_HAS_CONTENTS) != 0) { bfd_size_type stabsize, strsize; bfd_byte *stabs, *strings; bfd_byte *stab; bfd_size_type stroff, next_stroff; - stabsize = bfd_section_size (sec); - stabs = (bfd_byte *) xmalloc (stabsize); - if (! bfd_get_section_contents (abfd, sec, stabs, 0, stabsize)) + if (!bfd_malloc_and_get_section (abfd, sec, &stabs)) { fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), names[i].secname, bfd_errmsg (bfd_get_error ())); free (shandle); - free (stabs); return false; } - strsize = bfd_section_size (strsec); - strings = (bfd_byte *) xmalloc (strsize + 1); - if (! bfd_get_section_contents (abfd, strsec, strings, 0, strsize)) + if (!bfd_malloc_and_get_section (abfd, strsec, &strings)) { fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), names[i].strsecname, bfd_errmsg (bfd_get_error ())); free (shandle); - free (strings); free (stabs); return false; } /* Zero terminate the strings table, just in case. */ - strings [strsize] = 0; + strsize = bfd_section_size (strsec); + strings [strsize - 1] = 0; if (shandle == NULL) { shandle = start_stab (dhandle, abfd, true, syms, symcount); @@ -165,6 +163,7 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount, stroff = 0; next_stroff = 0; + stabsize = bfd_section_size (sec); /* PR 17512: file: 078-60391-0.001:0.1. */ for (stab = stabs; stab <= (stabs + stabsize) - 12; stab += 12) { |