Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(825)

Unified Diff: utility/vbutil_kernel.c

Issue 3764004: Handle short read error correctly in vbutil_kernel.c (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utility/vbutil_kernel.c
diff --git a/utility/vbutil_kernel.c b/utility/vbutil_kernel.c
index 391f5ad284722d1b22776518e3d816f5599700ab..23b6eb2f0cffb71156e40aab579185ddd9ea91f8 100644
--- a/utility/vbutil_kernel.c
+++ b/utility/vbutil_kernel.c
@@ -128,6 +128,16 @@ static void Debug(const char *format, ...) {
va_end(ap);
}
+/* Return an explanation when fread() fails. */
+static const char *error_fread(FILE *fp) {
+ const char *retval = "beats me why";
+ if (feof(fp))
+ retval = "EOF";
+ else if (ferror(fp))
+ retval = strerror(errno);
+ clearerr(fp);
+ return retval;
+}
/* Return the smallest integral multiple of [alignment] that is equal
* to or greater than [val]. Used to determine the number of
@@ -385,7 +395,7 @@ static blob_t *OldBlob(const char* filename) {
}
if (0 != stat(filename, &statbuf)) {
- error("unable to stat %s: %s\n", filename, strerror(errno));
+ error("Unable to stat %s: %s\n", filename, strerror(errno));
return 0;
}
@@ -409,7 +419,7 @@ static blob_t *OldBlob(const char* filename) {
}
if (1 != fread(buf, DEFAULT_PADDING, 1, fp)) {
- error("Unable to read header from %s: %s\n", filename, strerror(errno));
+ error("Unable to read header from %s: %s\n", filename, error_fread(fp));
goto unwind_oldblob;
}
@@ -460,6 +470,11 @@ static blob_t *OldBlob(const char* filename) {
Debug(" bootloader_size = 0x%" PRIx64 "\n", bp->bootloader_size);
Debug(" blob_size = 0x%" PRIx64 "\n", bp->blob_size);
+ if (!bp->blob_size) {
+ error("No kernel blob found\n");
+ goto unwind_oldblob;
+ }
+
bp->blob = (uint8_t *)Malloc(bp->blob_size);
if (!bp->blob) {
error("Couldn't allocate 0x%" PRIx64 " bytes for blob_t.\n", bp->blob_size);
@@ -468,7 +483,7 @@ static blob_t *OldBlob(const char* filename) {
/* read it in */
if (1 != fread(bp->blob, bp->blob_size, 1, fp)) {
- error("Unable to read kernel blob from %s: %s\n", filename, strerror(errno));
+ error("Unable to read kernel blob from %s: %s\n", filename, error_fread(fp));
goto unwind_oldblob;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698