Bug 23686, two segment faults in nm

Fixes the bugs exposed by the testcases in the PR, plus two more bugs
I noticed when looking at _bfd_stab_section_find_nearest_line.

	PR 23686
	* dwarf2.c (read_section): Error when attempting to malloc
	"(bfd_size_type) -1".
	* syms.c (_bfd_stab_section_find_nearest_line): Bounds check
	function_name.  Bounds check reloc address.  Formatting.  Ensure
	.stabstr zero terminated.
This commit is contained in:
Alan Modra
2018-09-20 15:29:17 +09:30
parent 4ee9b0c53a
commit 3083813299
3 changed files with 33 additions and 7 deletions

View File

@@ -527,6 +527,7 @@ read_section (bfd * abfd,
asection *msec;
const char *section_name = sec->uncompressed_name;
bfd_byte *contents = *section_buffer;
bfd_size_type amt;
/* The section may have already been read. */
if (contents == NULL)
@@ -549,7 +550,13 @@ read_section (bfd * abfd,
*section_size = msec->rawsize ? msec->rawsize : msec->size;
/* Paranoia - alloc one extra so that we can make sure a string
section is NUL terminated. */
contents = (bfd_byte *) bfd_malloc (*section_size + 1);
amt = *section_size + 1;
if (amt == 0)
{
bfd_set_error (bfd_error_no_memory);
return FALSE;
}
contents = (bfd_byte *) bfd_malloc (amt);
if (contents == NULL)
return FALSE;
if (syms