summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Garber <jgarber1@ualberta.ca>2019-05-08 16:28:27 -0600
committerPatrick Georgi <pgeorgi@google.com>2019-05-13 09:12:35 +0000
commit4fbd22e38d42faf7654cf9ded1f4001652e7fd37 (patch)
treed5a5e400a6e7655ecfbf9032b6cb69188176da91
parent2be617b58b500214d45c338eda88237730524cac (diff)
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>
-rw-r--r--util/intelvbttool/intelvbttool.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/util/intelvbttool/intelvbttool.c b/util/intelvbttool/intelvbttool.c
index 715b39ad57..2dfa0023f2 100644
--- a/util/intelvbttool/intelvbttool.c
+++ b/util/intelvbttool/intelvbttool.c
@@ -788,7 +788,20 @@ static void parse_vbt(const struct fileobject *fo,
}
/* 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 */