Whamcloud - gitweb
LU-4629 utils: fix NULL pointer dereference 36/10136/4
authorDmitry Eremin <dmitry.eremin@intel.com>
Mon, 28 Apr 2014 20:00:58 +0000 (00:00 +0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 11 Jun 2014 02:46:36 +0000 (02:46 +0000)
'uuid' and 'lnet' can be NULL. So check for this case.

Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
Change-Id: I06ead7470649054ca5bd0e0395f5e817c08bc2db
Reviewed-on: http://review.whamcloud.com/10136
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/lustre_cfg.c
lustre/utils/nidlist.c

index 03b1dc5..5042aac 100644 (file)
@@ -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)
index 78e70ce..3b04d32 100644 (file)
@@ -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)