diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-09 17:07:53 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-09 17:08:54 +0000 |
| commit | 8f719f80b8f8b9dc128e902d1d2b94ee5c26a070 (patch) | |
| tree | 2730dfd0f118f97e0d04af9de6610db11fa2cdaf | |
| parent | 61015dbc6c1050a21454eb891c38ee5408c4a154 (diff) | |
util/nvmutil: safer calculated_checksum
we rely on uint16_t wrapping, but some platforms may
behave weirdly.
cast as uint32_t and then cast back, on return, with
an explicit mask beforehand.
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/nvmutil/nvmutil.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index c069cc6e..d84cd1c8 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1132,12 +1132,12 @@ static uint16_t calculated_checksum(size_t p) { size_t c; - uint16_t val16 = 0; + uint32_t val16 = 0; for (c = 0; c < NVM_CHECKSUM_WORD; c++) - val16 += nvm_word(c, p); + val16 += (uint32_t)nvm_word(c, p); - return NVM_CHECKSUM - val16; + return (uint16_t)((NVM_CHECKSUM - val16) & 0xffff); } /* |
