diff options
author | Alan Modra <amodra@gmail.com> | 2023-10-24 15:22:00 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-10-25 11:12:11 +1030 |
commit | 220be060180d14a0512bfb39b22341a7368822ae (patch) | |
tree | 237ed8b728c5729eced0bb4b66a5839cf040b841 /bfd/som.c | |
parent | e3afa685584773d3ae85f33dc9e6e42ecf604a53 (diff) | |
download | gdb-220be060180d14a0512bfb39b22341a7368822ae.zip gdb-220be060180d14a0512bfb39b22341a7368822ae.tar.gz gdb-220be060180d14a0512bfb39b22341a7368822ae.tar.bz2 |
asan: out of memory in som_set_reloc_info
Sections without SEC_HAS_CONTENTS avoid the file size checks, and of
course it doesn't make sense to read such as the contents are all
zero.
* som.c (som_set_reloc_info): Don't read sections without contents.
Diffstat (limited to 'bfd/som.c')
-rw-r--r-- | bfd/som.c | 38 |
1 files changed, 20 insertions, 18 deletions
@@ -5146,28 +5146,30 @@ som_set_reloc_info (unsigned char *fixup, section contents. */ rptr->addend = var ('V'); - if (rptr->addend == 0 && !section->contents) + if (rptr->addend == 0 + && (section->flags & SEC_HAS_CONTENTS) != 0) { - /* Got to read the damn contents first. We don't - bother saving the contents (yet). Add it one - day if the need arises. */ - bfd_byte *contents; - if (!bfd_malloc_and_get_section (section->owner, section, - &contents)) + if (!section->contents) { - free (contents); - return (unsigned) -1; + /* Got to read the damn contents first. We don't + bother saving the contents (yet). Add it one + day if the need arises. */ + bfd_byte *contents; + if (!bfd_malloc_and_get_section (section->owner, + section, &contents)) + { + free (contents); + return (unsigned) -1; + } + section->contents = contents; + deallocate_contents = 1; } - section->contents = contents; - deallocate_contents = 1; + if (offset - var ('L') <= section->size + && section->size - (offset - var ('L')) >= 4) + rptr->addend = bfd_get_32 (section->owner, + (section->contents + + offset - var ('L'))); } - if (rptr->addend == 0 - && offset - var ('L') <= section->size - && section->size - (offset - var ('L')) >= 4) - rptr->addend = bfd_get_32 (section->owner, - (section->contents - + offset - var ('L'))); - } else rptr->addend = var ('V'); |