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

d396ed
--- binutils.orig/bfd/dwarf2.c	2019-11-13 11:49:52.211121564 +0000
d396ed
+++ binutils-2.33.1/bfd/dwarf2.c	2019-11-13 11:53:26.991423055 +0000
d396ed
@@ -2813,8 +2813,8 @@ static bfd_boolean comp_unit_maybe_decod
d396ed
 
d396ed
 static bfd_boolean
d396ed
 find_abstract_instance (struct comp_unit *   unit,
d396ed
-			bfd_byte *           orig_info_ptr,
d396ed
 			struct attribute *   attr_ptr,
d396ed
+			unsigned int         recur_count,
d396ed
 			const char **        pname,
d396ed
 			bfd_boolean *        is_linkage,
d396ed
 			char **              filename_ptr,
d396ed
@@ -2829,6 +2829,14 @@ find_abstract_instance (struct comp_unit
d396ed
   struct attribute attr;
d396ed
   const char *name = NULL;
d396ed
 
d396ed
+  if (recur_count == 100)
d396ed
+    {
d396ed
+      _bfd_error_handler
d396ed
+       (_("DWARF error: abstract instance recursion detected"));
d396ed
+      bfd_set_error (bfd_error_bad_value);
d396ed
+      return FALSE;
d396ed
+    }
d396ed
+
d396ed
   /* DW_FORM_ref_addr can reference an entry in a different CU. It
d396ed
      is an offset from the .debug_info section, not the current CU.  */
d396ed
   if (attr_ptr->form == DW_FORM_ref_addr)
d396ed
@@ -2962,15 +2970,7 @@ find_abstract_instance (struct comp_unit
d396ed
 					 info_ptr, info_ptr_end);
d396ed
 	      if (info_ptr == NULL)
d396ed
 		break;
d396ed
-	      /* It doesn't ever make sense for DW_AT_specification to
d396ed
-		 refer to the same DIE.  Stop simple recursion.  */
d396ed
-	      if (info_ptr == orig_info_ptr)
d396ed
-		{
d396ed
-		  _bfd_error_handler
d396ed
-		    (_("DWARF error: abstract instance recursion detected"));
d396ed
-		  bfd_set_error (bfd_error_bad_value);
d396ed
-		  return FALSE;
d396ed
-		}
d396ed
+
d396ed
 	      switch (attr.name)
d396ed
 		{
d396ed
 		case DW_AT_name:
d396ed
@@ -2984,7 +2984,7 @@ find_abstract_instance (struct comp_unit
d396ed
 		    }
d396ed
 		  break;
d396ed
 		case DW_AT_specification:
d396ed
-		  if (!find_abstract_instance (unit, info_ptr, &attr,
d396ed
+		  if (!find_abstract_instance (unit, &attr, recur_count + 1,
d396ed
 					       &name, is_linkage,
d396ed
 					       filename_ptr, linenumber_ptr))
d396ed
 		    return FALSE;
d396ed
@@ -3200,7 +3200,7 @@ scan_unit_for_symbols (struct comp_unit
d396ed
 
d396ed
 		case DW_AT_abstract_origin:
d396ed
 		case DW_AT_specification:
d396ed
-		  if (!find_abstract_instance (unit, info_ptr, &attr,
d396ed
+		  if (!find_abstract_instance (unit, &attr, 0,
d396ed
 					       &func->name,
d396ed
 					       &func->is_linkage,
d396ed
 					       &func->file,