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

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