* Sanity check read_section_stabs_debugging_info
@ 2023-03-14 2:05 Alan Modra
0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2023-03-14 2:05 UTC (permalink / raw)
To: binutils
* rddbg.c (read_section_stabs_debugging_info): Exclude sections
without contents. Use bfd_malloc_and_get_section. Don't alloc
one extra for strings.
diff --git a/binutils/rddbg.c b/binutils/rddbg.c
index 036a74fc16a..f2ed6bcb3dd 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)
{
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Sanity check read_section_stabs_debugging_info
@ 2023-03-16 0:55 Alan Modra
0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2023-03-16 0:55 UTC (permalink / raw)
To: binutils
* rddbg.c (read_section_stabs_debugging_info): Don't segfault on
zero size string section.
diff --git a/binutils/rddbg.c b/binutils/rddbg.c
index f2ed6bcb3dd..1a888778312 100644
--- a/binutils/rddbg.c
+++ b/binutils/rddbg.c
@@ -147,7 +147,8 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
}
/* Zero terminate the strings table, just in case. */
strsize = bfd_section_size (strsec);
- strings [strsize - 1] = 0;
+ if (strsize != 0)
+ strings [strsize - 1] = 0;
if (shandle == NULL)
{
shandle = start_stab (dhandle, abfd, true, syms, symcount);
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-16 0:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-14 2:05 Sanity check read_section_stabs_debugging_info Alan Modra
2023-03-16 0:55 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).