summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Georgi <patrick@georgi-clan.de>2014-08-03 12:18:45 +0200
committerPatrick Georgi <patrick@georgi-clan.de>2014-08-03 15:19:28 +0200
commit38fa6edf2db155383e04bf8427377b7b684cede3 (patch)
tree4e7f8e85e810554f88122149c0e1ce158757d720
parent440daf786a85f8c1f4959c519811e3d6e10586bc (diff)
ifdtool: Check if file was opened
Check if the new file could in fact be opened before writing to it. Change-Id: I6b2d31bf5c18f657fca4dc14fee2f2d5a2e33080 Found-by: Coverity Scan Signed-off-by: Patrick Georgi <patrick@georgi-clan.de> Reviewed-on: http://review.coreboot.org/6477 Tested-by: build bot (Jenkins) Reviewed-by: Edward O'Callaghan <eocallaghan@alterapraxis.com> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
-rw-r--r--util/ifdtool/ifdtool.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c
index deef1b1fee..c4785504d5 100644
--- a/util/ifdtool/ifdtool.c
+++ b/util/ifdtool/ifdtool.c
@@ -540,6 +540,10 @@ static void write_regions(char *image, int size)
region_fd = open(region_filename(i),
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (region_fd < 0) {
+ perror("Error while trying to open file");
+ exit(EXIT_FAILURE);
+ }
if (write(region_fd, image + region.base, region.size) != region.size)
perror("Error while writing");
close(region_fd);
@@ -562,6 +566,10 @@ static void write_image(char *filename, char *image, int size)
new_fd = open(new_filename,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ if (new_fd < 0) {
+ perror("Error while trying to open file");
+ exit(EXIT_FAILURE);
+ }
if (write(new_fd, image, size) != size)
perror("Error while writing");
close(new_fd);