util/intelvbttool: Add error checking for memory allocation

It is possible that 'malloc_fo_sub' and 'remalloc_fo' can
fail, so add appropriate error checks for those cases.
This incidentally fixes a possible memory leak when
'malloc_fo_sub' succeeds but 'remalloc_fo' does not.

Found-by: Coverity Scan #1396050
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Change-Id: I944b67f5cdcfd7a687e81d8bb01a209c9dc9b0b8
Reviewed-on: https://review.coreboot.org/c/coreboot/+/32696
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Patrick Rudolph <siro@das-labor.org>
This commit is contained in:
Jacob Garber 2019-05-08 16:28:27 -06:00 committed by Patrick Georgi
parent 2be617b58b
commit 4fbd22e38d
1 changed files with 14 additions and 1 deletions

View File

@ -788,7 +788,20 @@ static void parse_vbt(const struct fileobject *fo,
} }
/* Duplicate fo as caller is owner and remalloc frees the object */ /* Duplicate fo as caller is owner and remalloc frees the object */
*vbt = remalloc_fo(malloc_fo_sub(fo, 0), head->vbt_size); struct fileobject *dupfo = malloc_fo_sub(fo, 0);
if (!dupfo) {
printerr("malloc failed\n");
return;
}
struct fileobject *newfo = remalloc_fo(dupfo, head->vbt_size);
if (!newfo) {
printerr("remalloc failed\n");
free_fo(dupfo);
return;
}
*vbt = newfo;
} }
/* Option ROM checksum */ /* Option ROM checksum */