[binutils-gdb] xcoff armap traversal
Alan Modra
amodra@sourceware.org
Mon Nov 9 22:52:44 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=86a70c3fe7d5d629732cadf00b1f79c55f0782c8
commit 86a70c3fe7d5d629732cadf00b1f79c55f0782c8
Author: Alan Modra <amodra@gmail.com>
Date: Tue Nov 10 08:39:46 2026 +1030
xcoff armap traversal
oss-fuzz found a bug in code matching armap symbol names against bfds.
It's possible to run off the end of the armap, resulting in an
unitialised read or if you're really lucky, a read buffer overflow.
* coff-rs6000.c (xcoff_write_armap_big): Move armap count test
to correct loop.
Diff:
---
bfd/coff-rs6000.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index c1adcd5ed49..beefbc14800 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -2052,11 +2052,11 @@ xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
i = 0;
for (current_bfd = abfd->archive_head;
- current_bfd != NULL && i < orl_count;
+ current_bfd != NULL;
current_bfd = current_bfd->archive_next)
{
arch_info = bfd_get_arch_info (current_bfd);
- while (map[i].abfd == current_bfd)
+ while (i < orl_count && map[i].abfd == current_bfd)
{
string_length = strlen (map[i].name) + 1;
if (arch_info->bits_per_address == 64)
@@ -2150,10 +2150,10 @@ xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
/* loop over the 32 bit offsets */
i = 0;
archive_iterator_begin (&iterator, abfd);
- while (i < orl_count && archive_iterator_next (&iterator))
+ while (archive_iterator_next (&iterator))
{
arch_info = bfd_get_arch_info (iterator.current.member);
- while (map[i].abfd == iterator.current.member)
+ while (i < orl_count && map[i].abfd == iterator.current.member)
{
if (arch_info->bits_per_address == 32)
{
@@ -2167,11 +2167,11 @@ xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
/* loop over the 32 bit symbol names */
i = 0;
for (current_bfd = abfd->archive_head;
- current_bfd != NULL && i < orl_count;
+ current_bfd != NULL;
current_bfd = current_bfd->archive_next)
{
arch_info = bfd_get_arch_info (current_bfd);
- while (map[i].abfd == current_bfd)
+ while (i < orl_count && map[i].abfd == current_bfd)
{
if (arch_info->bits_per_address == 32)
{
@@ -2234,10 +2234,10 @@ xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
/* loop over the 64 bit offsets */
i = 0;
archive_iterator_begin (&iterator, abfd);
- while (i < orl_count && archive_iterator_next (&iterator))
+ while (archive_iterator_next (&iterator))
{
arch_info = bfd_get_arch_info (iterator.current.member);
- while (map[i].abfd == iterator.current.member)
+ while (i < orl_count && map[i].abfd == iterator.current.member)
{
if (arch_info->bits_per_address == 64)
{
@@ -2251,11 +2251,11 @@ xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
/* loop over the 64 bit symbol names */
i = 0;
for (current_bfd = abfd->archive_head;
- current_bfd != NULL && i < orl_count;
+ current_bfd != NULL;
current_bfd = current_bfd->archive_next)
{
arch_info = bfd_get_arch_info (current_bfd);
- while (map[i].abfd == current_bfd)
+ while (i < orl_count && map[i].abfd == current_bfd)
{
if (arch_info->bits_per_address == 64)
{
More information about the Binutils-cvs
mailing list