gas: segfault in out_debug_str

Message ID aeXD6PoTmHjtu1iC@squeak.grove.modra.org
State New
Headers
Series gas: segfault in out_debug_str |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply

Commit Message

Alan Modra April 20, 2026, 6:12 a.m. UTC
  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.
  

Patch

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