[coreboot-gerrit] Change in coreboot[master]: util/amdfwtool/amdfwtool.c: Check for negative return

Richard Spiegel (Code Review) gerrit at coreboot.org
Wed Jan 17 18:25:04 CET 2018


Richard Spiegel has uploaded this change for review. ( https://review.coreboot.org/23303


Change subject: util/amdfwtool/amdfwtool.c: Check for negative return
......................................................................

util/amdfwtool/amdfwtool.c: Check for negative return

File open function <open()> will return -1 if there's any error. Check that
the return is grater or equal to 0 before using fstat(). Print error message
and exit if there's an error.

This fixes CIDs 1353018, 1353020, 1353027 and 1353028

BUG=b:72062481
TEST=Build no errors

Change-Id: I77d6973d1ad1eadb93922866e618038045be5937
Signed-off-by: Richard Spiegel <richard.spiegel at silverbackltd.com>
---
M util/amdfwtool/amdfwtool.c
1 file changed, 15 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/03/23303/1

diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c
index 61c2a05..4374c73 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -292,6 +292,11 @@
 	for (i = 0; fw_table[i].type != AMD_FW_INVALID; i++) {
 		if (fw_table[i].filename != NULL) {
 			fd = open(fw_table[i].filename, O_RDONLY);
+			if (fd < 0) {
+				printf("Error: %s\n", strerror(errno));
+				free(base);
+				exit(1);
+			}
 			fstat(fd, &fd_stat);
 
 			switch (fw_table[i].type) {
@@ -349,6 +354,16 @@
 			pspdir[4+4*i+0] = fw_table[i].type;
 
 			fd = open(fw_table[i].filename, O_RDONLY);
+			if (fd < 0) {
+				printf("Error: %s\n", strerror(errno));
+				free(base);
+				exit(1);
+			}
+			if (fd < 0) {
+				printf("Error: %s\n", strerror(errno));
+				free(base);
+				exit(1);
+			}
 			fstat(fd, &fd_stat);
 			pspdir[4+4*i+1] = (uint32_t)fd_stat.st_size;
 

-- 
To view, visit https://review.coreboot.org/23303
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I77d6973d1ad1eadb93922866e618038045be5937
Gerrit-Change-Number: 23303
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Spiegel <richard.spiegel at silverbackltd.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180117/8f8709f5/attachment-0001.html>


More information about the coreboot-gerrit mailing list