From b44c311db72c91dd7122a0254503e8c444e5a1b6 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 27 Jan 2025 04:09:48 +0000 Subject: [PATCH] util/nvmutil swap(): ensure that no overflow occurs it wouldn't occur, on the current logic, but i wasn't comfortable having the starting point (on little endian) being higher than the checked endpoint, in case of possible integer overflow as a result of future modifications. this is therefore a pre-emptive bug fix, because it doesn't yet fix a bug, but it prevents a bug from being introduced. Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index f8eb384..729f283 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -441,7 +441,7 @@ swap(int partnum) /* swaps bytes in words, not pointers. */ size_t w, x; uint8_t *n = (uint8_t *) gbe[partnum]; - for (w = nf * ((uint8_t *) &e)[0], x = 1; w < NVM_SIZE; + for (w = NVM_SIZE * ((uint8_t *) &e)[0], x = 1; w < NVM_SIZE; w += 2, x += 2) { n[w] ^= n[x]; n[x] ^= n[w];