[binutils-gdb] gas: segfault in out_debug_str

Alan Modra via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f2830d95872ebd4234e66f87ec4eb3f73f2d079e

commit f2830d95872ebd4234e66f87ec4eb3f73f2d079e
Author: Alan Modra <[email protected]>
Date:   Mon Apr 20 15:39:39 2026 +0930

    gas: segfault in out_debug_str
    
    Another fuzzer fix.  I don't care to emit diagnostics for silly input,
    so haven't done so here.
    
            * dwarf2dbg.c (out_debug_str): Don't segfault on NULL file name.

Diff:
---
 gas/dwarf2dbg.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index c9057213118..7b338bb11cd 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -3058,9 +3058,14 @@ out_debug_str (segT str_seg, symbolS **name_sym, symbolS **comp_dir_sym,
 #endif
       free (dirname);
     }
-  len = strlen (files[first_file].filename) + 1;
-  p = frag_more (len);
-  memcpy (p, files[first_file].filename, len);
+  if (files[first_file].filename)
+    {
+      len = strlen (files[first_file].filename) + 1;
+      p = frag_more (len);
+      memcpy (p, files[first_file].filename, len);
+    }
+  else
+    frag_append_1_char (0);
 
   /* DW_AT_comp_dir */
   *comp_dir_sym = symbol_temp_new_now_octets ();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.