mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-19 09:32:27 +02:00
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>
This commit is contained in:
@@ -1132,12 +1132,12 @@ static uint16_t
|
|||||||
calculated_checksum(size_t p)
|
calculated_checksum(size_t p)
|
||||||
{
|
{
|
||||||
size_t c;
|
size_t c;
|
||||||
uint16_t val16 = 0;
|
uint32_t val16 = 0;
|
||||||
|
|
||||||
for (c = 0; c < NVM_CHECKSUM_WORD; c++)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user