[coreboot-gerrit] New patch to review for coreboot: 1b87cb9 cbfstool: more error handling

Patrick Georgi (patrick@georgi-clan.de) gerrit at coreboot.org
Sat Aug 9 17:49:29 CEST 2014


Patrick Georgi (patrick at georgi-clan.de) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6565

-gerrit

commit 1b87cb92fb9b2011df334255ee9fe413e1a7353e
Author: Patrick Georgi <patrick at georgi-clan.de>
Date:   Sat Aug 9 17:48:38 2014 +0200

    cbfstool: more error handling
    
    ftell() returns -1 on error, cover that.
    (and as a bonus fseek(), too)
    
    Change-Id: I319a8b75fc44549b611b6b1557a8969595914129
    Found-by: Coverity Scan
    Signed-off-by: Patrick Georgi <patrick at georgi-clan.de>
---
 util/cbfstool/common.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index b746c86..56eee6c 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -59,8 +59,15 @@ int buffer_from_file(struct buffer *buffer, const char *filename) {
 		perror(filename);
 		return -1;
 	}
-	fseek(fp, 0, SEEK_END);
+	if (fseek(fp, 0, SEEK_END) == -1) {
+		perror(filename);
+		return -1;
+	}
 	buffer->size = ftell(fp);
+	if (buffer->size == -1) {
+		perror(filename);
+		return -1;
+	}
 	buffer->name = strdup(filename);
 	rewind(fp);
 	buffer->data = (char *)malloc(buffer->size);



More information about the coreboot-gerrit mailing list