Blame SOURCES/gdb-rhbz1708192-parse_macro_definition-crash.patch

501b51
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
501b51
From: Sergio Durigan Junior <sergiodj@redhat.com>
501b51
Date: Fri, 10 May 2019 16:57:26 -0400
501b51
Subject: gdb-rhbz1708192-parse_macro_definition-crash.patch
501b51
501b51
;; "Fix" segfault that happens on parse_macro_definition because
501b51
;; debugedit corrupts the .debug_macro section.
501b51
;; Sergio Durigan Junior, RH BZ 1708192.
501b51
501b51
Don't crash if dwarf_decode_macro_bytes's 'body' is NULL
501b51
501b51
Hi,
501b51
501b51
Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192
501b51
      https://bugzilla.redhat.com/show_bug.cgi?id=1708786
501b51
501b51
During the Fedora RPM build process, gdb-add-index is invoked to
501b51
extract the DWARF index from the binary, and GDB will segfault because
501b51
dwarf2read.c:parse_definition_macro's 'body' variable is NULL.
501b51
501b51
The underlying problem is that Fedora's rpm-build's "debugedit"
501b51
program will silently corrupt .debug_macro strings when a binary is
501b51
compiled with -g3.  This is being taken care of by Mark Wielaard,
501b51
here:
501b51
501b51
  https://bugzilla.redhat.com/show_bug.cgi?id=1708786
501b51
501b51
However, I still feel it's important to make GDB more resilient
501b51
against invalid DWARF input, so I'm proposing this rather simple patch
501b51
to catch the situation when "body == NULL" (i.e., it's probably been
501b51
corrupted) and issue a complaint.  This is not a real fix to the
501b51
problem, of course, but at least GDB is able to finish without
501b51
segfaulting.
501b51
501b51
OK for master?
501b51
501b51
gdb/ChangeLog:
501b51
2019-05-15  Sergio Durigan Junior  <sergiodj@redhat.com>
501b51
501b51
	Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192
501b51
	* dwarf2read.c (dwarf_decode_macro_bytes): Check whether 'body' is
501b51
	NULL, and complain if that's the case.
501b51
501b51
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
501b51
--- a/gdb/dwarf2read.c
501b51
+++ b/gdb/dwarf2read.c
501b51
@@ -24355,7 +24355,21 @@ dwarf_decode_macro_bytes (struct dwarf2_per_objfile *dwarf2_per_objfile,
501b51
 			 is_define ? _("definition") : _("undefinition"),
501b51
 			 line == 0 ? _("zero") : _("non-zero"), line, body);
501b51
 
501b51
-	    if (is_define)
501b51
+	    if (body == NULL)
501b51
+	      {
501b51
+		/* Fedora's rpm-build's "debugedit" binary
501b51
+		   corrupted .debug_macro sections.
501b51
+
501b51
+		   For more info, see
501b51
+		   https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */
501b51
+		complaint (_("debug info gives %s invalid macro %s "
501b51
+			     "without body (corrupted?) at line %d "
501b51
+			     "on file %s"),
501b51
+			   at_commandline ? _("command-line") : _("in-file"),
501b51
+			   is_define ? _("definition") : _("undefinition"),
501b51
+			   line, current_file->filename);
501b51
+	      }
501b51
+	    else if (is_define)
501b51
 	      parse_macro_definition (current_file, line, body);
501b51
 	    else
501b51
 	      {