From 54abe281c91edc1e564afbb233779418b887e625 Mon Sep 17 00:00:00 2001 From: Dmitry Eremin Date: Tue, 29 Apr 2014 00:00:58 +0400 Subject: [PATCH] LU-4629 utils: fix NULL pointer dereference 'uuid' and 'lnet' can be NULL. So check for this case. Signed-off-by: Dmitry Eremin Change-Id: I06ead7470649054ca5bd0e0395f5e817c08bc2db Reviewed-on: http://review.whamcloud.com/10136 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: James Simmons Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/utils/lustre_cfg.c | 22 +++++++++++----------- lustre/utils/nidlist.c | 28 ++++++++++++++++------------ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/lustre/utils/lustre_cfg.c b/lustre/utils/lustre_cfg.c index 03b1dc5..5042aac 100644 --- a/lustre/utils/lustre_cfg.c +++ b/lustre/utils/lustre_cfg.c @@ -270,22 +270,20 @@ int jt_obd_cleanup(int argc, char **argv) static int do_add_uuid(char * func, char *uuid, lnet_nid_t nid) { - int rc; - struct lustre_cfg_bufs bufs; - struct lustre_cfg *lcfg; + int rc; + struct lustre_cfg_bufs bufs; + struct lustre_cfg *lcfg; - lustre_cfg_bufs_reset(&bufs, lcfg_devname); - if (uuid) - lustre_cfg_bufs_set_string(&bufs, 1, uuid); + lustre_cfg_bufs_reset(&bufs, lcfg_devname); + if (uuid != NULL) + lustre_cfg_bufs_set_string(&bufs, 1, uuid); lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs); if (lcfg == NULL) { rc = -ENOMEM; } else { lcfg->lcfg_nid = nid; - /* Poison NAL -- pre 1.4.6 will LASSERT on 0 NAL, this way it - * doesn't work without crashing (bz 10130) */ - lcfg->lcfg_nal = 0x5a; + rc = lcfg_ioctl(func, OBD_DEV_ID, lcfg); lustre_cfg_free(lcfg); } @@ -295,8 +293,10 @@ int do_add_uuid(char * func, char *uuid, lnet_nid_t nid) return -1; } - printf ("Added uuid %s: %s\n", uuid, libcfs_nid2str(nid)); - return 0; + if (uuid != NULL) + printf("Added uuid %s: %s\n", uuid, libcfs_nid2str(nid)); + + return 0; } int jt_lcfg_add_uuid(int argc, char **argv) diff --git a/lustre/utils/nidlist.c b/lustre/utils/nidlist.c index 78e70ce..3b04d32 100644 --- a/lustre/utils/nidlist.c +++ b/lustre/utils/nidlist.c @@ -209,20 +209,24 @@ static char *nl_nid_lookup_ipaddr(char *nid) if ((p = strchr(name, '.'))) *p = '\0'; len = strlen(name) + 2; - if (lnet) + if (lnet != NULL) len += strlen(lnet); - if (!(res = malloc(len))) - nl_oom(); - snprintf(res, len, "%s@%s", name, lnet); - break; - } - } - freeaddrinfo(ai); - } - } - free(addr); + if (!(res = malloc(len))) + nl_oom(); + if (lnet != NULL) + snprintf(res, len, "%s@%s", + name, lnet); + else + snprintf(res, len, "%s", name); + break; + } + } + freeaddrinfo(ai); + } + } + free(addr); - return res; + return res; } void nl_lookup_ip(NIDList nl) -- 1.8.3.1