]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Avoid trigger an assertion failure in the STABS parser by replacing the abort with...
authorNick Clifton <nickc@redhat.com>
Mon, 23 Mar 2020 16:17:51 +0000 (16:17 +0000)
committerNick Clifton <nickc@redhat.com>
Mon, 23 Mar 2020 16:19:07 +0000 (16:19 +0000)
PR 25714
* wrstabs.c (stab_pop_type): Replace assertion with error return.
* write_stabs_in_sections_debugging_info: Likewise.
* stab_enum_type: Likewise.
* stab_modify_type: Likewise.
* stab_struct_field: Likewise.
* stab_end_struct_type: Likewise.
* stab_start_class_type: Likewise.
* stab_class_static_member: Likewise.
* stab_class_baseclass: Likewise.
* stab_class_start_method: Likewise.
* stab_class_method_var: Likewise.
* stab_class_end_method: Likewise.
* stab_end_class_type: Likewise.
* stab_typedef_type: Likewise.
* stab_start_function: Likewise.
* stab_end_block: Likewise.
* stab_lineno: Likewise.

binutils/ChangeLog
binutils/wrstabs.c

index de41d8d66660e9f0f2d955b7c3ede5e421242148..bad19ea8b296440ebb30e4ffdc1b7f0d24b37210 100644 (file)
@@ -1,3 +1,24 @@
+2020-03-23  Nick Clifton  <nickc@redhat.com>
+
+       PR 25714
+       * wrstabs.c (stab_pop_type): Replace assertion with error return.
+       * write_stabs_in_sections_debugging_info: Likewise.
+       * stab_enum_type: Likewise.
+       * stab_modify_type: Likewise.
+       * stab_struct_field: Likewise.
+       * stab_end_struct_type: Likewise.
+       * stab_start_class_type: Likewise.
+       * stab_class_static_member: Likewise.
+       * stab_class_baseclass: Likewise.
+       * stab_class_start_method: Likewise.
+       * stab_class_method_var: Likewise.
+       * stab_class_end_method: Likewise.
+       * stab_end_class_type: Likewise.
+       * stab_typedef_type: Likewise.
+       * stab_start_function: Likewise.
+       * stab_end_block: Likewise.
+       * stab_lineno: Likewise.
+
 2020-03-20  Nick Clifton  <nickc@redhat.com>
 
        * readelf.c (get_compression_header): Add ATTRIBUTE_WARN_UNUSED_RESULT.
index 34c9ef9d2db9fa3030333ddb2d8f2c72b6970565..86abec2765c9a96f35003afc72cde9ac14390e5a 100644 (file)
@@ -437,7 +437,8 @@ stab_pop_type (struct stab_write_handle *info)
   char *ret;
 
   s = info->type_stack;
-  assert (s != NULL);
+  if (s == NULL)
+    return NULL;
 
   info->type_stack = s->next;
 
@@ -511,7 +512,8 @@ write_stabs_in_sections_debugging_info (bfd *abfd, void *dhandle,
   if (! debug_write (dhandle, &stab_fns, (void *) &info))
     return FALSE;
 
-  assert (info.pending_lbrac == (bfd_vma) -1);
+  if (info.pending_lbrac != (bfd_vma) -1)
+    return FALSE;
 
   /* Output a trailing N_SO.  */
   if (! stab_write_symbol (&info, N_SO, 0, info.last_text_address,
@@ -788,7 +790,8 @@ stab_enum_type (void *p, const char *tag, const char **names,
 
   if (names == NULL)
     {
-      assert (tag != NULL);
+      if (tag == NULL)
+       return FALSE;
 
       buf = (char *) xmalloc (10 + strlen (tag));
       sprintf (buf, "xe%s:", tag);
@@ -850,7 +853,8 @@ stab_modify_type (struct stab_write_handle *info, int mod,
   long tindex;
   char *s, *buf;
 
-  assert (info->type_stack != NULL);
+  if (info->type_stack == NULL)
+    return FALSE;
   targindex = info->type_stack->index;
 
   if (targindex <= 0
@@ -1360,8 +1364,9 @@ stab_struct_field (void *p, const char *name, bfd_vma bitpos,
 
   /* Add this field to the end of the current struct fields, which is
      currently on the top of the stack.  */
+  if (info->type_stack->fields == NULL)
+    return FALSE;
 
-  assert (info->type_stack->fields != NULL);
   n = (char *) xmalloc (strlen (info->type_stack->fields)
                        + strlen (name)
                        + strlen (s)
@@ -1416,7 +1421,8 @@ stab_end_struct_type (void *p)
   unsigned int size;
   char *fields, *first, *buf;
 
-  assert (info->type_stack != NULL && info->type_stack->fields != NULL);
+  if (info->type_stack == NULL || info->type_stack->fields == NULL)
+    return FALSE;
 
   definition = info->type_stack->definition;
   tindex = info->type_stack->index;
@@ -1463,13 +1469,15 @@ stab_start_class_type (void *p, const char *tag, unsigned int id,
 
       if (ownvptr)
        {
-         assert (info->type_stack->index > 0);
+         if (info->type_stack->index < 1)
+           return FALSE;
          vtable = (char *) xmalloc (20);
          sprintf (vtable, "~%%%ld", info->type_stack->index);
        }
       else
        {
-         assert (vstring);
+         if (vstring == NULL)
+           return FALSE;
          vtable = (char *) xmalloc (strlen (vstring) + 3);
          sprintf (vtable, "~%%%s", vstring);
          free (vstring);
@@ -1499,7 +1507,8 @@ stab_class_static_member (void *p, const char *name, const char *physname,
   /* Add this field to the end of the current struct fields, which is
      currently on the top of the stack.  */
 
-  assert (info->type_stack->fields != NULL);
+  if (info->type_stack->fields == NULL)
+    return FALSE;
   n = (char *) xmalloc (strlen (info->type_stack->fields)
                        + strlen (name)
                        + strlen (s)
@@ -1579,7 +1588,8 @@ stab_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean is_virtual,
 
   /* Add the new baseclass to the existing ones.  */
 
-  assert (info->type_stack != NULL && info->type_stack->fields != NULL);
+  if (info->type_stack == NULL || info->type_stack->fields == NULL)
+    return FALSE;
 
   if (info->type_stack->baseclasses == NULL)
     c = 0;
@@ -1611,7 +1621,8 @@ stab_class_start_method (void *p, const char *name)
   struct stab_write_handle *info = (struct stab_write_handle *) p;
   char *m;
 
-  assert (info->type_stack != NULL && info->type_stack->fields != NULL);
+  if (info->type_stack == NULL || info->type_stack->fields == NULL)
+    return FALSE;
 
   if (info->type_stack->methods == NULL)
     {
@@ -1656,7 +1667,8 @@ stab_class_method_var (struct stab_write_handle *info, const char *physname,
       context = stab_pop_type (info);
     }
 
-  assert (info->type_stack != NULL && info->type_stack->methods != NULL);
+  if (info->type_stack == NULL || info->type_stack->methods == NULL)
+    return FALSE;
 
   switch (visibility)
     {
@@ -1757,7 +1769,8 @@ stab_class_end_method (void *p)
 {
   struct stab_write_handle *info = (struct stab_write_handle *) p;
 
-  assert (info->type_stack != NULL && info->type_stack->methods != NULL);
+  if (info->type_stack == NULL || info->type_stack->methods == NULL)
+    return FALSE;
 
   /* We allocated enough room on info->type_stack->methods to add the
      trailing semicolon.  */
@@ -1776,7 +1789,10 @@ stab_end_class_type (void *p)
   unsigned int i = 0;
   char *buf;
 
-  assert (info->type_stack != NULL && info->type_stack->fields != NULL);
+  if (info->type_stack == NULL
+      || info->type_stack->string == NULL
+      || info->type_stack->fields == NULL)
+    return FALSE;
 
   /* Work out the size we need to allocate for the class definition.  */
 
@@ -1849,7 +1865,8 @@ stab_typedef_type (void *p, const char *name)
   struct string_hash_entry *h;
 
   h = string_hash_lookup (&info->typedef_hash, name, FALSE, FALSE);
-  assert (h != NULL && h->index > 0);
+  if (h == NULL || h->index < 1)
+    return FALSE;
 
   return stab_push_defined_type (info, h->index, h->size);
 }
@@ -2081,7 +2098,8 @@ stab_start_function (void *p, const char *name, bfd_boolean globalp)
   struct stab_write_handle *info = (struct stab_write_handle *) p;
   char *rettype, *buf;
 
-  assert (info->nesting == 0 && info->fun_offset == -1);
+  if (info->nesting != 0 || info->fun_offset != -1)
+    return FALSE;
 
   rettype = stab_pop_type (info);
 
@@ -2223,7 +2241,8 @@ stab_end_block (void *p, bfd_vma addr)
       info->pending_lbrac = (bfd_vma) -1;
     }
 
-  assert (info->nesting > 0);
+  if (info->nesting < 1)
+    return FALSE;
 
   --info->nesting;
 
@@ -2250,7 +2269,8 @@ stab_lineno (void *p, const char *file, unsigned long lineno, bfd_vma addr)
 {
   struct stab_write_handle *info = (struct stab_write_handle *) p;
 
-  assert (info->lineno_filename != NULL);
+  if (info->lineno_filename == NULL)
+    return FALSE;
 
   if (addr > info->last_text_address)
     info->last_text_address = addr;