From d56e433a7914cdf1ad6db64f7b10506336a8def9 Mon Sep 17 00:00:00 2001
From: Alan Modra <amodra@gmail.com>
Date: Wed, 15 Mar 2023 10:26:24 +1030
Subject: [PATCH] Re: Sanity check read_section_stabs_debugging_info

	* rddbg.c (read_section_stabs_debugging_info): Don't segfault on
	zero size string section.
---
 binutils/rddbg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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);
-- 
GitLab