From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: ubsan: integer overflow in section filepos subtraction
Date: Sat, 1 Jan 2022 15:46:55 +1030 [thread overview]
Message-ID: <Yc/jx7NsR2X4Zztg@squeak.grove.modra.org> (raw)
* elf.c (assign_file_positions_for_non_load_sections): Avoid
signed integer overflow.
diff --git a/bfd/elf.c b/bfd/elf.c
index 92c06f2e44f..d8a270d5219 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -6289,8 +6289,7 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
Elf_Internal_Shdr *hdr = &elf_section_data (sect)->this_hdr;
if (hdr->sh_type != SHT_NOBITS)
{
- p->p_filesz = (sect->filepos - m->sections[0]->filepos
- + hdr->sh_size);
+ p->p_filesz = sect->filepos - p->p_offset + hdr->sh_size;
/* NB: p_memsz of the loadable PT_NOTE segment
should be the same as p_filesz. */
if (p->p_type == PT_NOTE
--
Alan Modra
Australia Development Lab, IBM
reply other threads:[~2022-01-01 5:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yc/jx7NsR2X4Zztg@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).