bfd/elf-attrs.c: Fix possible infinite loop parsing attributes

Handle the case of a zero length section or sub-section in
_bfd_elf_parse_attributes and in doing so prevent an infinite loop
in the parser.

bfd/ChangeLog:

2014-11-06  Will Newton  <will.newton@linaro.org>

	* elf-attrs.c (_bfd_elf_parse_attributes): Handle zero
	length sections and sub-sections.
This commit is contained in:
Will Newton 2014-11-05 15:24:30 +00:00
parent f321b03772
commit 1fe9dc4519
2 changed files with 9 additions and 0 deletions

View File

@ -1,3 +1,8 @@
2014-11-06 Will Newton <will.newton@linaro.org>
* elf-attrs.c (_bfd_elf_parse_attributes): Handle zero
length sections and sub-sections.
2014-11-04 Nick Clifton <nickc@redhat.com>
PR binutils/17512

View File

@ -455,6 +455,8 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
section_len = bfd_get_32 (abfd, p);
p += 4;
if (section_len == 0)
break;
if (section_len > len)
section_len = len;
len -= section_len;
@ -487,6 +489,8 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
p += n;
subsection_len = bfd_get_32 (abfd, p);
p += 4;
if (subsection_len == 0)
break;
if (subsection_len > section_len)
subsection_len = section_len;
section_len -= subsection_len;