mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-29 07:53:44 +02:00
flashrom.c: Validate before allocate in verify_range()
Simplify a goto away for free'ing a buffer by validating before attempting to allocate. BUG=none TEST=builds Change-Id: Iae886f203d1c59ae9a89421f7483a4ec3f747256 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/59372 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
parent
ea0ae153dd
commit
43f998274f
18
flashrom.c
18
flashrom.c
@ -417,6 +417,13 @@ int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int sta
|
|||||||
if (!len)
|
if (!len)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (start + len > flash->chip->total_size * 1024) {
|
||||||
|
msg_gerr("Error: %s called with start 0x%x + len 0x%x >"
|
||||||
|
" total_size 0x%x\n", __func__, start, len,
|
||||||
|
flash->chip->total_size * 1024);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!flash->chip->read) {
|
if (!flash->chip->read) {
|
||||||
msg_cerr("ERROR: flashrom has no read function for this flash chip.\n");
|
msg_cerr("ERROR: flashrom has no read function for this flash chip.\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -427,17 +434,8 @@ int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int sta
|
|||||||
msg_gerr("Could not allocate memory!\n");
|
msg_gerr("Could not allocate memory!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (start + len > flash->chip->total_size * 1024) {
|
int ret = flash->chip->read(flash, readbuf, start, len);
|
||||||
msg_gerr("Error: %s called with start 0x%x + len 0x%x >"
|
|
||||||
" total_size 0x%x\n", __func__, start, len,
|
|
||||||
flash->chip->total_size * 1024);
|
|
||||||
ret = -1;
|
|
||||||
goto out_free;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = flash->chip->read(flash, readbuf, start, len);
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
msg_gerr("Verification impossible because read failed "
|
msg_gerr("Verification impossible because read failed "
|
||||||
"at 0x%x (len 0x%x)\n", start, len);
|
"at 0x%x (len 0x%x)\n", start, len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user