asan: _bfd_elf_parse_attributes heap buffer overflow
authorAlan Modra <amodra@gmail.com>
Tue, 25 May 2021 04:06:20 +0000 (13:36 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 25 May 2021 05:37:08 +0000 (15:07 +0930)
commit4be1e8dbb3f8da8058ed93dfc222ee6dffb02e60
tree80e545d4cf7a8bc7386b0af657b6efefb905123a
parente63e5f9f9f9c7922dfc348b1637d1fd0a2b353d2
asan: _bfd_elf_parse_attributes heap buffer overflow

I exposed a problem with the change in commit 574ec1084d to the outer
loop of _bfd_elf_parse_attributes.  "p_end - p >= 4" is better than
"p < p_end - 4" as far as pointer UB is concerned if the size of the
attritbute section is say, 3 bytes.  However you do need to ensure p
never exceeds p_end, and that length remaining is kept consistent with
the pointer.

* elf-attrs.c (elf_attr_strdup): New function.
(_bfd_elf_attr_strdup): Use it here.
(elf_add_obj_attr_string): New function, extracted from..
(bfd_elf_add_obj_attr_string): ..here.
(elf_add_obj_attr_int_string): New function, extracted from..
(bfd_elf_add_obj_attr_int_string): ..here.
(_bfd_elf_parse_attributes): Don't allocate an extra byte for a
string terminator.  Instead ensure parsing doesn't go past
end of sub-section.  Use size_t variables for lengths.
bfd/ChangeLog
bfd/elf-attrs.c
This page took 0.029571 seconds and 4 git commands to generate.