public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* ubsan: integer overflow in section filepos subtraction
@ 2022-01-01  5:16 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-01-01  5:16 UTC (permalink / raw)
  To: binutils

	* 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-01  5:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-01  5:16 ubsan: integer overflow in section filepos subtraction 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).