* [binutils-gdb] bfd: Avoid signed overflow for new_size adjustment
@ 2022-12-06 22:48 H.J. Lu
0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2022-12-06 22:48 UTC (permalink / raw)
To: bfd-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e25466730d436937e814f80b69e5d124513fff03
commit e25466730d436937e814f80b69e5d124513fff03
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Tue Dec 6 12:54:43 2022 -0800
bfd: Avoid signed overflow for new_size adjustment
When bfd_size_type is unsigned 64-bit integer and sizeof is unsigned
32-bit integer, subtraction in
*new_size += sizeof (Elf32_External_Chdr) - sizeof (Elf64_External_Chdr);
will overflow. Use
*new_size -= sizeof (Elf64_External_Chdr) - sizeof (Elf32_External_Chdr);
to avoid overflow.
PR binutils/29860
* compress.c (bfd_convert_section_setup): Avoid signed overflow
for new_size adjustment.
Diff:
---
bfd/compress.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bfd/compress.c b/bfd/compress.c
index bb55a6ec0ac..5ea7cd95f3a 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -306,7 +306,7 @@ bfd_convert_section_setup (bfd *ibfd, asection *isec, bfd *obfd,
if (hdr_size == sizeof (Elf32_External_Chdr))
*new_size += sizeof (Elf64_External_Chdr) - sizeof (Elf32_External_Chdr);
else
- *new_size += sizeof (Elf32_External_Chdr) - sizeof (Elf64_External_Chdr);
+ *new_size -= sizeof (Elf64_External_Chdr) - sizeof (Elf32_External_Chdr);
return true;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-06 22:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06 22:48 [binutils-gdb] bfd: Avoid signed overflow for new_size adjustment H.J. Lu
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).