91 lines
2.9 KiB
Diff
91 lines
2.9 KiB
Diff
|
|
From 6d4f8af90e2256f58c9e02ad72c3dd37201a7349 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Alan Modra <amodra@gmail.com>
|
||
|
|
Date: Wed, 9 Oct 2019 00:07:29 +1030
|
||
|
|
Subject: [PATCH] PR25078, stack overflow in function find_abstract_instance
|
||
|
|
|
||
|
|
PR 25078
|
||
|
|
* dwarf2.c (find_abstract_instance): Delete orig_info_ptr, add
|
||
|
|
recur_count. Error on recur_count reaching 100 rather than
|
||
|
|
info_ptr matching orig_info_ptr. Adjust calls.
|
||
|
|
---
|
||
|
|
bfd/dwarf2.c | 35 +++++++++++++++++------------------
|
||
|
|
1 file changed, 17 insertions(+), 18 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
|
||
|
|
index 26bfb25eb3..d05af5af9c 100644
|
||
|
|
--- a/bfd/dwarf2.c
|
||
|
|
+++ b/bfd/dwarf2.c
|
||
|
|
@@ -2803,13 +2803,13 @@ lookup_symbol_in_variable_table (struct comp_unit *unit,
|
||
|
|
}
|
||
|
|
|
||
|
|
static bfd_boolean
|
||
|
|
-find_abstract_instance (struct comp_unit * unit,
|
||
|
|
- bfd_byte * orig_info_ptr,
|
||
|
|
- struct attribute * attr_ptr,
|
||
|
|
- const char ** pname,
|
||
|
|
- bfd_boolean * is_linkage,
|
||
|
|
- char ** filename_ptr,
|
||
|
|
- int * linenumber_ptr)
|
||
|
|
+find_abstract_instance (struct comp_unit *unit,
|
||
|
|
+ struct attribute *attr_ptr,
|
||
|
|
+ unsigned int recur_count,
|
||
|
|
+ const char **pname,
|
||
|
|
+ bfd_boolean *is_linkage,
|
||
|
|
+ char **filename_ptr,
|
||
|
|
+ int *linenumber_ptr)
|
||
|
|
{
|
||
|
|
bfd *abfd = unit->abfd;
|
||
|
|
bfd_byte *info_ptr;
|
||
|
|
@@ -2820,6 +2820,14 @@ find_abstract_instance (struct comp_unit * unit,
|
||
|
|
struct attribute attr;
|
||
|
|
const char *name = NULL;
|
||
|
|
|
||
|
|
+ if (recur_count == 100)
|
||
|
|
+ {
|
||
|
|
+ _bfd_error_handler
|
||
|
|
+ (_("DWARF error: abstract instance recursion detected"));
|
||
|
|
+ bfd_set_error (bfd_error_bad_value);
|
||
|
|
+ return FALSE;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
/* DW_FORM_ref_addr can reference an entry in a different CU. It
|
||
|
|
is an offset from the .debug_info section, not the current CU. */
|
||
|
|
if (attr_ptr->form == DW_FORM_ref_addr)
|
||
|
|
@@ -2937,15 +2945,6 @@ find_abstract_instance (struct comp_unit * unit,
|
||
|
|
info_ptr, info_ptr_end);
|
||
|
|
if (info_ptr == NULL)
|
||
|
|
break;
|
||
|
|
- /* It doesn't ever make sense for DW_AT_specification to
|
||
|
|
- refer to the same DIE. Stop simple recursion. */
|
||
|
|
- if (info_ptr == orig_info_ptr)
|
||
|
|
- {
|
||
|
|
- _bfd_error_handler
|
||
|
|
- (_("DWARF error: abstract instance recursion detected"));
|
||
|
|
- bfd_set_error (bfd_error_bad_value);
|
||
|
|
- return FALSE;
|
||
|
|
- }
|
||
|
|
switch (attr.name)
|
||
|
|
{
|
||
|
|
case DW_AT_name:
|
||
|
|
@@ -2959,7 +2958,7 @@ find_abstract_instance (struct comp_unit * unit,
|
||
|
|
}
|
||
|
|
break;
|
||
|
|
case DW_AT_specification:
|
||
|
|
- if (!find_abstract_instance (unit, info_ptr, &attr,
|
||
|
|
+ if (!find_abstract_instance (unit, &attr, recur_count + 1,
|
||
|
|
&name, is_linkage,
|
||
|
|
filename_ptr, linenumber_ptr))
|
||
|
|
return FALSE;
|
||
|
|
@@ -3173,7 +3172,7 @@ scan_unit_for_symbols (struct comp_unit *unit)
|
||
|
|
|
||
|
|
case DW_AT_abstract_origin:
|
||
|
|
case DW_AT_specification:
|
||
|
|
- if (!find_abstract_instance (unit, info_ptr, &attr,
|
||
|
|
+ if (!find_abstract_instance (unit, &attr, 0,
|
||
|
|
&func->name,
|
||
|
|
&func->is_linkage,
|
||
|
|
&func->file,
|
||
|
|
--
|
||
|
|
2.19.1
|
||
|
|
|