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

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