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

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