From 776eee721d1e6e6424eb4cf75d7bf9c63b26bd04 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Tue, 3 Mar 2026 19:41:21 +0000 Subject: 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 --- util/nvmutil/nvmutil.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'util/nvmutil/nvmutil.c') 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 -- cgit v1.2.1