ubsan: bfd_mach_o_build_commands shift exponent 64 is too large
authorAlan Modra <amodra@gmail.com>
Sat, 1 Jan 2022 03:23:06 +0000 (13:53 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 1 Jan 2022 03:52:13 +0000 (14:22 +1030)
* mach-o.c (bfd_mach_o_read_section_32): Limit alignment further.
(bfd_mach_o_read_section_64): Likewise.

bfd/mach-o.c

index d90ea3c28ce7274259b1a2793c41c7a1f8be2170..af5ce024a0f4365d36390ecbb94912c6c1649696 100644 (file)
@@ -3653,12 +3653,12 @@ bfd_mach_o_read_section_32 (bfd *abfd, unsigned long prot)
   section->offset = bfd_h_get_32 (abfd, raw.offset);
   section->align = bfd_h_get_32 (abfd, raw.align);
   /* PR 17512: file: 0017eb76.  */
-  if (section->align > 64)
+  if (section->align >= 31)
     {
       _bfd_error_handler
-       (_("bfd_mach_o_read_section_32: overlarge alignment value: %#lx, "
-          "using 32 instead"), section->align);
-      section->align = 32;
+       (_("bfd_mach_o_read_section_32: overlarge alignment value: %#lx"),
+        section->align);
+      section->align = 30;
     }
   section->reloff = bfd_h_get_32 (abfd, raw.reloff);
   section->nreloc = bfd_h_get_32 (abfd, raw.nreloc);
@@ -3696,12 +3696,12 @@ bfd_mach_o_read_section_64 (bfd *abfd, unsigned long prot)
   section->size = bfd_h_get_64 (abfd, raw.size);
   section->offset = bfd_h_get_32 (abfd, raw.offset);
   section->align = bfd_h_get_32 (abfd, raw.align);
-  if (section->align > 64)
+  if (section->align >= 63)
     {
       _bfd_error_handler
-       (_("bfd_mach_o_read_section_64: overlarge alignment value: %#lx, "
-          "using 32 instead"), section->align);
-      section->align = 32;
+       (_("bfd_mach_o_read_section_64: overlarge alignment value: %#lx"),
+        section->align);
+      section->align = 62;
     }
   section->reloff = bfd_h_get_32 (abfd, raw.reloff);
   section->nreloc = bfd_h_get_32 (abfd, raw.nreloc);