Message ID | 1367886948-24481-1-git-send-email-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
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>
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>
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");