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

8c00d6
--- binutils.orig/libiberty/cp-demangle.c	2019-04-10 10:31:27.854997707 +0100
8c00d6
+++ binutils-2.31.1/libiberty/cp-demangle.c	2019-04-10 16:00:35.820350978 +0100
8c00d6
@@ -858,7 +858,7 @@ CP_STATIC_IF_GLIBCPP_V3
8c00d6
 int
8c00d6
 cplus_demangle_fill_name (struct demangle_component *p, const char *s, int len)
8c00d6
 {
8c00d6
-  if (p == NULL || s == NULL || len == 0)
8c00d6
+  if (p == NULL || s == NULL || len <= 0)
8c00d6
     return 0;
8c00d6
   p->d_printing = 0;
8c00d6
   p->type = DEMANGLE_COMPONENT_NAME;
8c00d6
@@ -4032,7 +4032,7 @@ d_growable_string_callback_adapter (cons
8c00d6
    are larger than the actual numbers encountered.  */
8c00d6
 
8c00d6
 static void
8c00d6
-d_count_templates_scopes (int *num_templates, int *num_scopes,
8c00d6
+d_count_templates_scopes (struct d_print_info *dpi,
8c00d6
 			  const struct demangle_component *dc)
8c00d6
 {
8c00d6
   if (dc == NULL)
8c00d6
@@ -4052,13 +4052,13 @@ d_count_templates_scopes (int *num_templ
8c00d6
       break;
8c00d6
 
8c00d6
     case DEMANGLE_COMPONENT_TEMPLATE:
8c00d6
-      (*num_templates)++;
8c00d6
+      dpi->num_copy_templates++;
8c00d6
       goto recurse_left_right;
8c00d6
 
8c00d6
     case DEMANGLE_COMPONENT_REFERENCE:
8c00d6
     case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
8c00d6
       if (d_left (dc)->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM)
8c00d6
-	(*num_scopes)++;
8c00d6
+	dpi->num_saved_scopes++;
8c00d6
       goto recurse_left_right;
8c00d6
 
8c00d6
     case DEMANGLE_COMPONENT_QUAL_NAME:
8c00d6
@@ -4122,42 +4122,42 @@ d_count_templates_scopes (int *num_templ
8c00d6
     case DEMANGLE_COMPONENT_TAGGED_NAME:
8c00d6
     case DEMANGLE_COMPONENT_CLONE:
8c00d6
     recurse_left_right:
8c00d6
-      d_count_templates_scopes (num_templates, num_scopes,
8c00d6
-				d_left (dc));
8c00d6
-      d_count_templates_scopes (num_templates, num_scopes,
8c00d6
-				d_right (dc));
8c00d6
+      /* PR 89394 - Check for too much recursion.  */
8c00d6
+      if (dpi->recursion > DEMANGLE_RECURSION_LIMIT)
8c00d6
+	/* FIXME: There ought to be a way to report to the
8c00d6
+	   user that the recursion limit has been reached.  */
8c00d6
+	return;
8c00d6
+
8c00d6
+      ++ dpi->recursion;
8c00d6
+      d_count_templates_scopes (dpi, d_left (dc));
8c00d6
+      d_count_templates_scopes (dpi, d_right (dc));
8c00d6
+      -- dpi->recursion;
8c00d6
       break;
8c00d6
 
8c00d6
     case DEMANGLE_COMPONENT_CTOR:
8c00d6
-      d_count_templates_scopes (num_templates, num_scopes,
8c00d6
-				dc->u.s_ctor.name);
8c00d6
+      d_count_templates_scopes (dpi, dc->u.s_ctor.name);
8c00d6
       break;
8c00d6
 
8c00d6
     case DEMANGLE_COMPONENT_DTOR:
8c00d6
-      d_count_templates_scopes (num_templates, num_scopes,
8c00d6
-				dc->u.s_dtor.name);
8c00d6
+      d_count_templates_scopes (dpi, dc->u.s_dtor.name);
8c00d6
       break;
8c00d6
 
8c00d6
     case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
8c00d6
-      d_count_templates_scopes (num_templates, num_scopes,
8c00d6
-				dc->u.s_extended_operator.name);
8c00d6
+      d_count_templates_scopes (dpi, dc->u.s_extended_operator.name);
8c00d6
       break;
8c00d6
 
8c00d6
     case DEMANGLE_COMPONENT_FIXED_TYPE:
8c00d6
-      d_count_templates_scopes (num_templates, num_scopes,
8c00d6
-                                dc->u.s_fixed.length);
8c00d6
+      d_count_templates_scopes (dpi, dc->u.s_fixed.length);
8c00d6
       break;
8c00d6
 
8c00d6
     case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
8c00d6
     case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
8c00d6
-      d_count_templates_scopes (num_templates, num_scopes,
8c00d6
-				d_left (dc));
8c00d6
+      d_count_templates_scopes (dpi, d_left (dc));
8c00d6
       break;
8c00d6
 
8c00d6
     case DEMANGLE_COMPONENT_LAMBDA:
8c00d6
     case DEMANGLE_COMPONENT_DEFAULT_ARG:
8c00d6
-      d_count_templates_scopes (num_templates, num_scopes,
8c00d6
-				dc->u.s_unary_num.sub);
8c00d6
+      d_count_templates_scopes (dpi, dc->u.s_unary_num.sub);
8c00d6
       break;
8c00d6
     }
8c00d6
 }
8c00d6
@@ -4192,8 +4192,12 @@ d_print_init (struct d_print_info *dpi,
8c00d6
   dpi->next_copy_template = 0;
8c00d6
   dpi->num_copy_templates = 0;
8c00d6
 
8c00d6
-  d_count_templates_scopes (&dpi->num_copy_templates,
8c00d6
-			    &dpi->num_saved_scopes, dc);
8c00d6
+  d_count_templates_scopes (dpi, dc);
8c00d6
+  /* If we did not reach the recursion limit, then reset the
8c00d6
+     current recursion value back to 0, so that we can print
8c00d6
+     the templates.  */
8c00d6
+  if (dpi->recursion < DEMANGLE_RECURSION_LIMIT)
8c00d6
+    dpi->recursion = 0;
8c00d6
   dpi->num_copy_templates *= dpi->num_saved_scopes;
8c00d6
 
8c00d6
   dpi->current_template = NULL;