aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2024-04-11 13:12:21 +0930
committerAlan Modra <amodra@gmail.com>2024-04-11 17:05:15 +0930
commitef70c9e7b26ec5e95b073944a9ed19d495c4fe88 (patch)
treec4e818d86b5eed141c67bc6ce550ddbb9bf41e6f /binutils
parentbf649e72d3d5bc0784080438f550095d71769904 (diff)
downloadgdb-ef70c9e7b26ec5e95b073944a9ed19d495c4fe88.zip
gdb-ef70c9e7b26ec5e95b073944a9ed19d495c4fe88.tar.gz
gdb-ef70c9e7b26ec5e95b073944a9ed19d495c4fe88.tar.bz2
Re: Update objcopy's --section-alignment option
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.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/objcopy.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index d9abfdf..d91ba12 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -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