From 401e101e0274d401e90e50cd8280a9ff36006477 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sun, 29 Dec 2019 12:56:04 +1030 Subject: [PATCH] ubsan: alpha-vms: shift exponent is too large * vms-alpha.c (_bfd_vms_slurp_egsd): Make base_addr a bfd_vma. Limit alignment power. Correct and simplify alignment expression. (evax_bfd_print_relocation_records): Avoid signed shift left. --- bfd/ChangeLog | 6 ++++++ bfd/vms-alpha.c | 17 ++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 807dc07ca05..a1e5273674e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2019-12-29 Alan Modra + + * vms-alpha.c (_bfd_vms_slurp_egsd): Make base_addr a bfd_vma. + Limit alignment power. Correct and simplify alignment expression. + (evax_bfd_print_relocation_records): Avoid signed shift left. + 2019-12-29 Alan Modra * vms-misc.c (_bfd_vms_save_sized_string): Add abfd param, make diff --git a/bfd/vms-alpha.c b/bfd/vms-alpha.c index 5d2ff527aa3..6a087611b4b 100644 --- a/bfd/vms-alpha.c +++ b/bfd/vms-alpha.c @@ -1180,7 +1180,7 @@ _bfd_vms_slurp_egsd (bfd *abfd) int gsd_type; unsigned int gsd_size; unsigned char *vms_rec; - unsigned long base_addr; + bfd_vma base_addr; vms_debug2 ((2, "EGSD\n")); @@ -1196,7 +1196,7 @@ _bfd_vms_slurp_egsd (bfd *abfd) PRIV (recrd.rec_size) -= 8; /* Calculate base address for each section. */ - base_addr = 0L; + base_addr = 0; while (PRIV (recrd.rec_size) > 4) { @@ -1244,7 +1244,7 @@ _bfd_vms_slurp_egsd (bfd *abfd) else { char *name; - unsigned long align_addr; + bfd_vma align_addr; name = _bfd_vms_save_counted_string (abfd, &egps->namlng, gsd_size - 4); @@ -1255,7 +1255,7 @@ _bfd_vms_slurp_egsd (bfd *abfd) section->filepos = 0; section->size = bfd_getl32 (egps->alloc); - section->alignment_power = egps->align; + section->alignment_power = egps->align & 31; vms_section_data (section)->flags = vms_flags; vms_section_data (section)->no_flags = 0; @@ -1283,10 +1283,9 @@ _bfd_vms_slurp_egsd (bfd *abfd) return FALSE; /* Give a non-overlapping vma to non absolute sections. */ - align_addr = (1 << section->alignment_power); - if ((base_addr % align_addr) != 0) - base_addr += (align_addr - (base_addr % align_addr)); - section->vma = (bfd_vma)base_addr; + align_addr = (bfd_vma) 1 << section->alignment_power; + base_addr = (base_addr + align_addr - 1) & -align_addr; + section->vma = base_addr; base_addr += section->size; } @@ -6648,7 +6647,7 @@ evax_bfd_print_relocation_records (FILE *file, const unsigned char *rel, fprintf (file, _(" bitmap: 0x%08x (count: %u):\n"), val, count); for (k = 0; k < 32; k++) - if (val & (1 << k)) + if (val & (1u << k)) { if (n == 0) fputs (" ", file); -- 2.30.2