From: Andreas Dilger Date: Fri, 23 Feb 2018 18:26:40 +0000 (-0700) Subject: LU-10658 utils: check mount_lustre for allocation failure X-Git-Tag: 2.11.0-RC1~19 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F00%2F31400%2F3;p=fs%2Flustre-release.git LU-10658 utils: check mount_lustre for allocation failure Check if calloc() failed and return an error rather than dereferencing the NULL pointer. Found by static analysis. Test-Parameters: trivial Signed-off-by: Andreas Dilger Change-Id: Ie4a5e3341fab1de77990fc99df54cdc562dcab07 Reviewed-on: https://review.whamcloud.com/31400 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Dmitry Eremin Reviewed-by: Bob Glossman Reviewed-by: Nathaniel Clark Reviewed-by: Oleg Drokin --- diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index fbfb1a0..b2c742b 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -285,6 +285,9 @@ int parse_options(struct mount_opts *mop, char *orig_options, int rc = 0; options = calloc(strlen(orig_options) + 1, 1); + if (options == NULL) + return ENOMEM; + *flagp = 0; nextopt = orig_options; while ((opt = strsep(&nextopt, ","))) { @@ -292,8 +295,7 @@ int parse_options(struct mount_opts *mop, char *orig_options, /* empty option */ continue; - /* Handle retries in a slightly different - * manner */ + /* Handle retries in a slightly different manner */ arg = opt; val = strchr(opt, '='); /* please note that some ldiskfs mount options are also in @@ -330,7 +332,7 @@ int parse_options(struct mount_opts *mop, char *orig_options, "%s: shared key path too long\n", progname); free(options); - return -1; + return EINVAL; } strncpy(mop->mo_skpath, val + 1, strlen(val + 1)); #endif @@ -805,7 +807,6 @@ int main(int argc, char *const argv[]) if (rc) { fprintf(stderr, "%s: can't parse options: %s\n", progname, options); - rc = EINVAL; goto out_options; }