]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Re: Update objcopy's --section-alignment option
authorAlan Modra <amodra@gmail.com>
Thu, 11 Apr 2024 03:42:21 +0000 (13:12 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 11 Apr 2024 07:35:15 +0000 (17:05 +0930)
ubsan: shift exponent 255 is too large for 64-bit type

I should have known oss-fuzz wouldn't be satisfied so easily.  The pef
format allows quite silly section alignments in object files.

* objcopy.c (setup_section): Limit shift exponent when checking
vma and lma for alignment.

binutils/objcopy.c

index d9abfdfbb39fdade7f2f2da0c192f02913126694..d91ba123c0126e756128fda2e9c2f8979bbea532 100644 (file)
@@ -4340,7 +4340,9 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
      and the VMA was not set by the user
      and the section does not have relocations associated with it
      then warn the user.  */
-  if ((osection->vma & (((bfd_vma) 1 << alignment) - 1)) != 0
+  if (osection->vma != 0
+      && (alignment >= sizeof (bfd_vma) * CHAR_BIT
+         || (osection->vma & (((bfd_vma) 1 << alignment) - 1)) != 0)
       && alignment != bfd_section_alignment (isection)
       && change_section_address == 0
       && ! vma_set_by_user
@@ -4352,7 +4354,9 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
   /* Similar check for a non-aligned LMA.
      FIXME: Since this is only an LMA, maybe it does not matter if
      it is not aligned ?  */
-  if ((osection->lma & (((bfd_vma) 1 << alignment) - 1)) != 0
+  if (osection->lma != 0
+      && (alignment >= sizeof (bfd_vma) * CHAR_BIT
+         || (osection->lma & (((bfd_vma) 1 << alignment) - 1)) != 0)
       && alignment != bfd_section_alignment (isection)
       && change_section_address == 0
       && ! lma_set_by_user