This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PR11302, segfault in _bfd_dwarf2_find_nearest_line
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Thu, 4 Mar 2010 11:11:28 +1030
- Subject: PR11302, segfault in _bfd_dwarf2_find_nearest_line
Applying mainline.
PR 11302
* dwarf2.c (read_abbrevs): Return NULL on alloc failures.
(read_attribute_value): Likewise.
(find_abstract_instance_name): Handle failure from read_attribute.
(scan_unit_for_symbols, parse_comp_unit): Likewise.
Index: bfd/dwarf2.c
===================================================================
RCS file: /cvs/src/src/bfd/dwarf2.c,v
retrieving revision 1.130
diff -u -p -r1.130 dwarf2.c
--- bfd/dwarf2.c 19 Jan 2010 23:17:57 -0000 1.130
+++ bfd/dwarf2.c 4 Mar 2010 00:17:09 -0000
@@ -646,10 +646,12 @@ read_abbrevs (bfd *abfd, bfd_uint64_t of
if (! read_section (abfd, ".debug_abbrev", ".zdebug_abbrev",
stash->syms, offset,
&stash->dwarf_abbrev_buffer, &stash->dwarf_abbrev_size))
- return 0;
+ return NULL;
amt = sizeof (struct abbrev_info*) * ABBREV_HASH_SIZE;
abbrevs = (struct abbrev_info **) bfd_zalloc (abfd, amt);
+ if (abbrevs == NULL)
+ return NULL;
abbrev_ptr = stash->dwarf_abbrev_buffer + offset;
abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
@@ -660,6 +662,8 @@ read_abbrevs (bfd *abfd, bfd_uint64_t of
{
amt = sizeof (struct abbrev_info);
cur_abbrev = (struct abbrev_info *) bfd_zalloc (abfd, amt);
+ if (cur_abbrev == NULL)
+ return NULL;
/* Read in abbrev header. */
cur_abbrev->number = abbrev_number;
@@ -773,6 +777,8 @@ read_attribute_value (struct attribute *
case DW_FORM_block2:
amt = sizeof (struct dwarf_block);
blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
+ if (blk == NULL)
+ return NULL;
blk->size = read_2_bytes (abfd, info_ptr);
info_ptr += 2;
blk->data = read_n_bytes (abfd, info_ptr, blk->size);
@@ -782,6 +788,8 @@ read_attribute_value (struct attribute *
case DW_FORM_block4:
amt = sizeof (struct dwarf_block);
blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
+ if (blk == NULL)
+ return NULL;
blk->size = read_4_bytes (abfd, info_ptr);
info_ptr += 4;
blk->data = read_n_bytes (abfd, info_ptr, blk->size);
@@ -811,6 +819,8 @@ read_attribute_value (struct attribute *
case DW_FORM_block:
amt = sizeof (struct dwarf_block);
blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
+ if (blk == NULL)
+ return NULL;
blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
info_ptr += bytes_read;
blk->data = read_n_bytes (abfd, info_ptr, blk->size);
@@ -820,6 +830,8 @@ read_attribute_value (struct attribute *
case DW_FORM_block1:
amt = sizeof (struct dwarf_block);
blk = (struct dwarf_block *) bfd_alloc (abfd, amt);
+ if (blk == NULL)
+ return NULL;
blk->size = read_1_byte (abfd, info_ptr);
info_ptr += 1;
blk->data = read_n_bytes (abfd, info_ptr, blk->size);
@@ -1838,7 +1850,10 @@ find_abstract_instance_name (struct comp
{
for (i = 0; i < abbrev->num_attrs; ++i)
{
- info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
+ info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit,
+ info_ptr);
+ if (info_ptr == NULL)
+ break;
switch (attr.name)
{
case DW_AT_name:
@@ -1858,7 +1873,7 @@ find_abstract_instance_name (struct comp
}
}
}
- return (name);
+ return name;
}
static void
@@ -1987,6 +2002,8 @@ scan_unit_for_symbols (struct comp_unit
for (i = 0; i < abbrev->num_attrs; ++i)
{
info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
+ if (info_ptr == NULL)
+ return FALSE;
if (func)
{
@@ -2231,6 +2248,8 @@ parse_comp_unit (struct dwarf2_debug *st
for (i = 0; i < abbrev->num_attrs; ++i)
{
info_ptr = read_attribute (&attr, &abbrev->attrs[i], unit, info_ptr);
+ if (info_ptr == NULL)
+ return NULL;
/* Store the data if it is of an attribute we want to keep in a
partial symbol table. */
--
Alan Modra
Australia Development Lab, IBM