]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ubsan: bfd.c:2519:8: shift exponent 34 is too large
authorAlan Modra <amodra@gmail.com>
Fri, 17 Dec 2021 02:32:55 +0000 (13:02 +1030)
committerAlan Modra <amodra@gmail.com>
Fri, 17 Dec 2021 05:31:17 +0000 (16:01 +1030)
* bfd.c (bfd_update_compression_header): Avoid integer overflow.

bfd/bfd.c

index 5c3797de3052b5715c6cb222599dbf5b2bd2e8f9..2eff8150023af752b8404d35d7277e6b1f6ff32a 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2504,7 +2504,7 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
              Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) contents;
              bfd_put_32 (abfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
              bfd_put_32 (abfd, sec->size, &echdr->ch_size);
-             bfd_put_32 (abfd, 1 << sec->alignment_power,
+             bfd_put_32 (abfd, 1u << sec->alignment_power,
                          &echdr->ch_addralign);
              /* bfd_log2 (alignof (Elf32_Chdr)) */
              bfd_set_section_alignment (sec, 2);
@@ -2516,7 +2516,7 @@ bfd_update_compression_header (bfd *abfd, bfd_byte *contents,
              bfd_put_32 (abfd, ELFCOMPRESS_ZLIB, &echdr->ch_type);
              bfd_put_32 (abfd, 0, &echdr->ch_reserved);
              bfd_put_64 (abfd, sec->size, &echdr->ch_size);
-             bfd_put_64 (abfd, 1 << sec->alignment_power,
+             bfd_put_64 (abfd, UINT64_C (1) << sec->alignment_power,
                          &echdr->ch_addralign);
              /* bfd_log2 (alignof (Elf64_Chdr)) */
              bfd_set_section_alignment (sec, 3);