* asan: out of memory in som_set_reloc_info
@ 2023-10-25 0:43 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-10-25 0:43 UTC (permalink / raw)
To: binutils
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.
diff --git a/bfd/som.c b/bfd/som.c
index d858b8b1468..dde1f1f8c47 100644
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -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');
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-10-25 0:43 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-25 0:43 asan: out of memory in som_set_reloc_info Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).