summaryrefslogtreecommitdiff
path: root/util/ifdtool
diff options
context:
space:
mode:
authorRonald G. Minnich <rminnich@gmail.com>2017-05-25 10:48:57 -0700
committerStefan Reinauer <stefan.reinauer@coreboot.org>2017-06-02 01:58:20 +0200
commit8db3c2a48549f28e40febae827666fe1730ebcd0 (patch)
tree248178cb3d6b5f7840d4e4954522ca0a2c2b3093 /util/ifdtool
parent8274f988d918fa9e1c2ecd45a8c912e75feca1c6 (diff)
downloadcoreboot-8db3c2a48549f28e40febae827666fe1730ebcd0.tar.xz
ifdtool: avoid potential unaligned pointer usage
In get_region, ifdtool assigns a not-known-to-be-aligned pointer to a uint32_t *. Now you know and I know that it is almost certainly aligned, but clang on OSX doesn't like this, and it's a dicey thing to do in any event, just waiting to hit someone hard at some future date. Assign the pointer to a void * and use memmove to copy the value to a uint32_t. This usage is more portable to all little-endian architectures, now, but is still not endian-safe. I doubt we'll ever care. Change-Id: Ifb2f260c3363ab0f5b4a59e5a4e0b5ecf049fa96 Signed-off-by: Ronald G. Minnich <rminnich@gmail.com> Reviewed-on: https://review.coreboot.org/19921 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'util/ifdtool')
-rw-r--r--util/ifdtool/ifdtool.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c
index 1024690423..9382bc4714 100644
--- a/util/ifdtool/ifdtool.c
+++ b/util/ifdtool/ifdtool.c
@@ -105,7 +105,8 @@ static region_t get_region(frba_t *frba, int region_type)
{
int base_mask;
int limit_mask;
- uint32_t *flreg;
+ uint32_t flreg;
+ void *v;
region_t region;
if (ifd_version >= IFD_VERSION_2)
@@ -117,39 +118,40 @@ static region_t get_region(frba_t *frba, int region_type)
switch (region_type) {
case 0:
- flreg = &frba->flreg0;
+ v = &frba->flreg0;
break;
case 1:
- flreg = &frba->flreg1;
+ v = &frba->flreg1;
break;
case 2:
- flreg = &frba->flreg2;
+ v = &frba->flreg2;
break;
case 3:
- flreg = &frba->flreg3;
+ v = &frba->flreg3;
break;
case 4:
- flreg = &frba->flreg4;
+ v = &frba->flreg4;
break;
case 5:
- flreg = &frba->flreg5;
+ v = &frba->flreg5;
break;
case 6:
- flreg = &frba->flreg6;
+ v = &frba->flreg6;
break;
case 7:
- flreg = &frba->flreg7;
+ v = &frba->flreg7;
break;
case 8:
- flreg = &frba->flreg8;
+ v = &frba->flreg8;
break;
default:
fprintf(stderr, "Invalid region type %d.\n", region_type);
exit (EXIT_FAILURE);
}
- region.base = (*flreg & base_mask) << 12;
- region.limit = ((*flreg & limit_mask) >> 4) | 0xfff;
+ memmove(&flreg, v, sizeof(flreg));
+ region.base = (flreg & base_mask) << 12;
+ region.limit = ((flreg & limit_mask) >> 4) | 0xfff;
region.size = region.limit - region.base + 1;
if (region.size < 0)