Patchwork lib: fwts_dump: check error return on mkdir

login
register
mail settings
Submitter Colin King
Date May 7, 2013, 12:35 a.m.
Message ID <1367886948-24481-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/241860/
State Accepted
Headers show

Comments

Colin King - May 7, 2013, 12:35 a.m.
From: Colin Ian King <colin.king@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@canonical.com>
---
 src/lib/src/fwts_dump.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Alex Hung - May 10, 2013, 1:09 a.m.
On 05/07/2013 08:35 AM, Colin King wrote:
> From: Colin Ian King <colin.king@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@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");
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - May 16, 2013, 4:10 a.m.
On 05/07/2013 08:35 AM, Colin King wrote:
> From: Colin Ian King <colin.king@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@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");
>
Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

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");