[PATCH] lib: fwts_dump: check error return on mkdir

Colin King colin.king at canonical.com
Tue May 7 00:35:48 UTC 2013


From: Colin Ian King <colin.king at canonical.com>

Coverity CID #997311, Unchecked return value from library

We should really check that mkdir failed or not rather than
assume it worked OK.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/src/fwts_dump.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/lib/src/fwts_dump.c b/src/lib/src/fwts_dump.c
index cbf6598..f3ccc15 100644
--- a/src/lib/src/fwts_dump.c
+++ b/src/lib/src/fwts_dump.c
@@ -248,9 +248,12 @@ int fwts_dump_info(fwts_framework *fw, const char *path)
 	if (path == NULL)
 		path = "./";
 
-	if (access(path, F_OK) != 0)
-		mkdir(path, 0777);
-
+	if (access(path, F_OK) != 0) {
+		if (mkdir(path, 0777) < 0) {
+			fprintf(stderr, "Cannot mkdir %s.\n", path);
+			return FWTS_ERROR;
+		}
+	}
 
 	if (dump_readme(path) != FWTS_OK)
 		fprintf(stderr, "Failed to dump README.txt.\n");
-- 
1.8.1.2




More information about the fwts-devel mailing list