summaryrefslogtreecommitdiffstats
path: root/layout.c
diff options
context:
space:
mode:
authorStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2015-12-25 21:59:45 +0000
committerStefan Tauner <stefan.tauner@alumni.tuwien.ac.at>2015-12-25 21:59:45 +0000
commit1668770c6fe7308939f208c265328a8ef92b6ac1 (patch)
treef787fd81606d11698acd1cec6a8d0f36c39d568f /layout.c
parentbcf6109a76a873fc1227402d4b5b13a87dc3eb1a (diff)
downloadast2050-flashrom-1668770c6fe7308939f208c265328a8ef92b6ac1.zip
ast2050-flashrom-1668770c6fe7308939f208c265328a8ef92b6ac1.tar.gz
Rigorously check integrity of I/O stream data
Even if fwrite() succeeds the data is not necessarily out of the clib's buffers and writing it eventually could fail. Even if the data is flushed out (explicitly by fflush() or implicitly by fclose()) the kernel might still hold a buffer. Previously we have ignored this to a large extent - even in important cases like writing the flash contents to a file. The results can be truncated images that would brick the respective machine if written back as is (though flashrom would not allow that due to a size mismatch). flashrom would not indicate the problem in any output - so far we only check the return value of fwrite() that is not conclusive. This patch checks the return values of all related system calls like fclose() unless we only read the file and are not really interested in output errors. In the latter case the return value is casted to void to document this fact. Additionally, this patch explicitly calls fflush() and fsync() (on regular files only) to do the best we can to guarantee the read image reaches the disk safely and at least inform the user if it did not work. Corresponding to flashrom svn r1902. Signed-off-by: Stefan Tauner <stefan.tauner@alumni.tuwien.ac.at> Acked-by: Urja Rannikko <urjaman@gmail.com>
Diffstat (limited to 'layout.c')
-rw-r--r--layout.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/layout.c b/layout.c
index 0b9f6e5..d039451 100644
--- a/layout.c
+++ b/layout.c
@@ -65,7 +65,7 @@ int read_romlayout(const char *name)
if (num_rom_entries >= MAX_ROMLAYOUT) {
msg_gerr("Maximum number of ROM images (%i) in layout "
"file reached.\n", MAX_ROMLAYOUT);
- fclose(romlayout);
+ (void)fclose(romlayout);
return 1;
}
if (2 != fscanf(romlayout, "%s %s\n", tempstr, rom_entries[num_rom_entries].name))
@@ -80,7 +80,7 @@ int read_romlayout(const char *name)
tstr2 = strtok(NULL, ":");
if (!tstr1 || !tstr2) {
msg_gerr("Error parsing layout file. Offending string: \"%s\"\n", tempstr);
- fclose(romlayout);
+ (void)fclose(romlayout);
return 1;
}
rom_entries[num_rom_entries].start = strtol(tstr1, (char **)NULL, 16);
@@ -95,7 +95,7 @@ int read_romlayout(const char *name)
rom_entries[i].end, rom_entries[i].name);
}
- fclose(romlayout);
+ (void)fclose(romlayout);
return 0;
}
OpenPOWER on IntegriCloud