From: Dmitry Eremin Date: Tue, 29 Mar 2016 15:09:47 +0000 (+0300) Subject: LU-7937 utils: Fix NULL pointer dereference X-Git-Tag: 2.8.53~49 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F94%2F19194%2F4;p=fs%2Flustre-release.git LU-7937 utils: Fix NULL pointer dereference Check the error of malloc() function and handle it properly. Change-Id: I2763d1b6d9c97c137a2593077ee31eaa3758ad81 Signed-off-by: Dmitry Eremin Reviewed-on: http://review.whamcloud.com/19194 Tested-by: Jenkins Reviewed-by: Bob Glossman Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/utils/lustre_cfg.c b/lustre/utils/lustre_cfg.c index 23ca708..19fdf66 100644 --- a/lustre/utils/lustre_cfg.c +++ b/lustre/utils/lustre_cfg.c @@ -569,6 +569,10 @@ static int jt_lcfg_mgsparam2(int argc, char **argv, struct param_opts *popt) /* put an '=' on the end in case it doesn't have one */ if (popt->po_delete && argv[i][len - 1] != '=') { buf = malloc(len + 1); + if (buf == NULL) { + rc = -ENOMEM; + break; + } sprintf(buf, "%s=", argv[i]); } else { buf = argv[i]; @@ -638,6 +642,10 @@ int jt_lcfg_mgsparam(int argc, char **argv) /* for delete, make it "=\0" */ buf = malloc(strlen(argv[optind]) + 2); + if (buf == NULL) { + rc = -ENOMEM; + goto out; + } /* put an '=' on the end in case it doesn't have one */ sprintf(buf, "%s=", argv[optind]); /* then truncate after the first '=' */ @@ -654,16 +662,19 @@ int jt_lcfg_mgsparam(int argc, char **argv) rc = -ENOMEM; } else { rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg); + if (rc < 0) + rc = -errno; lustre_cfg_free(lcfg); } - if (buf) - free(buf); - if (rc < 0) { - fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), - strerror(rc = errno)); - } + if (buf) + free(buf); +out: + if (rc < 0) { + fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]), + strerror(-rc)); + } - return rc; + return rc; } /**