summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-03 19:41:21 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-03 19:41:21 +0000
commit776eee721d1e6e6424eb4cf75d7bf9c63b26bd04 (patch)
treef54210aaf20e40cf4aed2cab9a50f6beb2786263
parentd88991f6bcd5def3790128c157ab32a8dfe61c3a (diff)
util/nvmutil: use memcpy in word/set_word
alignment isn't an issue, but aliasing between uintX_t types in C means that this code may fail on some weird systems. using memcpy here is advisable. Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--util/nvmutil/nvmutil.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index d60e2cbe..76bbea4d 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -488,8 +488,14 @@ good_checksum(int partnum)
static uint16_t
word(int pos16, int p)
{
+ uint16_t rval = 0;
check_bound(pos16, p);
- return ((uint16_t *) (buf + (SIZE_4KB * p)))[pos16];
+ (void) memcpy(
+ (uint8_t *) &rval,
+ (uint8_t *) (buf + (SIZE_4KB * p) + (pos16 << 1)),
+ sizeof(uint16_t)
+ );
+ return rval;
}
static void
@@ -497,7 +503,11 @@ set_word(int pos16, int p, uint16_t val16)
{
check_bound(pos16, p);
part_modified[p] = 1;
- ((uint16_t *) (buf + (SIZE_4KB * p)))[pos16] = val16;
+ (void) memcpy(
+ (uint8_t *) (buf + (SIZE_4KB * p) + (pos16 << 1)),
+ (uint8_t *) &val16,
+ sizeof(uint16_t)
+ );
}
static void