aboutsummaryrefslogtreecommitdiff
path: root/bfd/compress.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2022-12-06 12:54:43 -0800
committerH.J. Lu <hjl.tools@gmail.com>2022-12-06 14:47:44 -0800
commite25466730d436937e814f80b69e5d124513fff03 (patch)
tree2f1e54e0ea43df62e47d9f003900d604d88d38d1 /bfd/compress.c
parent53fd08b60d8183af2a6a6820677bfd01716bc992 (diff)
downloadbinutils-e25466730d436937e814f80b69e5d124513fff03.zip
binutils-e25466730d436937e814f80b69e5d124513fff03.tar.gz
binutils-e25466730d436937e814f80b69e5d124513fff03.tar.bz2
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.
Diffstat (limited to 'bfd/compress.c')
-rw-r--r--bfd/compress.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/bfd/compress.c b/bfd/compress.c
index bb55a6e..5ea7cd9 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;
}