From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 70ED7385828D; Tue, 14 Mar 2023 02:06:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70ED7385828D Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] Sanity check read_section_stabs_debugging_info X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: f049c18961236c3bf91409a060c1c9a709b96b44 X-Git-Newrev: 746598e07f7b666872bc31471de1b72de8a69c2b Message-Id: <20230314020632.70ED7385828D@sourceware.org> Date: Tue, 14 Mar 2023 02:06:32 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Mar 2023 02:06:32 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D746598e07f7b= 666872bc31471de1b72de8a69c2b commit 746598e07f7b666872bc31471de1b72de8a69c2b Author: Alan Modra Date: Tue Mar 14 10:11:58 2023 +1030 Sanity check read_section_stabs_debugging_info =20 * 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: --- binutils/rddbg.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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, =20 sec =3D bfd_get_section_by_name (abfd, names[i].secname); strsec =3D bfd_get_section_by_name (abfd, names[i].strsecname); - if (sec !=3D NULL && strsec !=3D NULL) + if (sec !=3D NULL + && (bfd_section_flags (sec) & SEC_HAS_CONTENTS) !=3D 0 + && strsec !=3D NULL + && (bfd_section_flags (strsec) & SEC_HAS_CONTENTS) !=3D 0) { bfd_size_type stabsize, strsize; bfd_byte *stabs, *strings; bfd_byte *stab; bfd_size_type stroff, next_stroff; =20 - stabsize =3D bfd_section_size (sec); - stabs =3D (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; } =20 - strsize =3D bfd_section_size (strsec); - strings =3D (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] =3D 0; + strsize =3D bfd_section_size (strsec); + strings [strsize - 1] =3D 0; if (shandle =3D=3D NULL) { shandle =3D start_stab (dhandle, abfd, true, syms, symcount); @@ -165,6 +163,7 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol *= *syms, long symcount, =20 stroff =3D 0; next_stroff =3D 0; + stabsize =3D bfd_section_size (sec); /* PR 17512: file: 078-60391-0.001:0.1. */ for (stab =3D stabs; stab <=3D (stabs + stabsize) - 12; stab +=3D 12) {