Blame SOURCES/binutils-CVE-2019-17450.patch

4ede5d
--- binutils.orig/bfd/dwarf2.c	2019-12-03 15:50:43.324118062 +0000
4ede5d
+++ binutils-2.30/bfd/dwarf2.c	2019-12-03 15:54:32.545489215 +0000
4ede5d
@@ -2803,8 +2803,8 @@ lookup_symbol_in_variable_table (struct
4ede5d
 
4ede5d
 static bfd_boolean
4ede5d
 find_abstract_instance_name (struct comp_unit *unit,
4ede5d
-			     bfd_byte *orig_info_ptr,
4ede5d
 			     struct attribute *attr_ptr,
4ede5d
+			     unsigned int recur_count,
4ede5d
 			     const char **pname,
4ede5d
 			     bfd_boolean *is_linkage)
4ede5d
 {
4ede5d
@@ -2817,6 +2817,14 @@ find_abstract_instance_name (struct comp
4ede5d
   struct attribute attr;
4ede5d
   const char *name = NULL;
4ede5d
 
4ede5d
+  if (recur_count == 100)
4ede5d
+    {
4ede5d
+      _bfd_error_handler
4ede5d
+       (_("DWARF error: abstract instance recursion detected"));
4ede5d
+      bfd_set_error (bfd_error_bad_value);
4ede5d
+      return FALSE;
4ede5d
+    }
4ede5d
+
4ede5d
   /* DW_FORM_ref_addr can reference an entry in a different CU. It
4ede5d
      is an offset from the .debug_info section, not the current CU.  */
4ede5d
   if (attr_ptr->form == DW_FORM_ref_addr)
4ede5d
@@ -2934,15 +2942,7 @@ find_abstract_instance_name (struct comp
4ede5d
 					 info_ptr, info_ptr_end);
4ede5d
 	      if (info_ptr == NULL)
4ede5d
 		break;
4ede5d
-	      /* It doesn't ever make sense for DW_AT_specification to
4ede5d
-		 refer to the same DIE.  Stop simple recursion.  */
4ede5d
-	      if (info_ptr == orig_info_ptr)
4ede5d
-		{
4ede5d
-		  _bfd_error_handler
4ede5d
-		    (_("Dwarf Error: Abstract instance recursion detected."));
4ede5d
-		  bfd_set_error (bfd_error_bad_value);
4ede5d
-		  return FALSE;
4ede5d
-		}
4ede5d
+
4ede5d
 	      switch (attr.name)
4ede5d
 		{
4ede5d
 		case DW_AT_name:
4ede5d
@@ -2956,7 +2956,7 @@ find_abstract_instance_name (struct comp
4ede5d
 		    }
4ede5d
 		  break;
4ede5d
 		case DW_AT_specification:
4ede5d
-		  if (!find_abstract_instance_name (unit, info_ptr, &attr,
4ede5d
+		  if (!find_abstract_instance_name (unit, &attr, recur_count + 1,
4ede5d
 						    pname, is_linkage))
4ede5d
 		    return FALSE;
4ede5d
 		  break;
4ede5d
@@ -3162,7 +3162,7 @@ scan_unit_for_symbols (struct comp_unit
4ede5d
 
4ede5d
 		case DW_AT_abstract_origin:
4ede5d
 		case DW_AT_specification:
4ede5d
-		  if (!find_abstract_instance_name (unit, info_ptr, &attr,
4ede5d
+		  if (!find_abstract_instance_name (unit, &attr, 0,
4ede5d
 						    &func->name,
4ede5d
 						    &func->is_linkage))
4ede5d
 		    goto fail;