Fix 'zpool create' segfault due to bad syntax
authorJorgen Lundman <lundman@lundman.net>
Thu, 29 Nov 2012 05:56:07 +0000 (14:56 +0900)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 4 Dec 2012 19:15:25 +0000 (11:15 -0800)
Incorrect syntax should never cause a segfault.  In this case
listing multiple comma delimited options after '-o' triggered
the problem.  For example:

  zpool create -o ashift=12,listsnaps=on

This patch resolves the issue by wrapping the calls which use
hdr with a NULL test.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #1118

lib/libzfs/libzfs_util.c

index 16affd1..4270087 100644 (file)
@@ -1297,8 +1297,9 @@ str2shift(libzfs_handle_t *hdl, const char *buf)
                        break;
        }
        if (i == strlen(ends)) {
-               zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
-                   "invalid numeric suffix '%s'"), buf);
+               if (hdl)
+                       zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
+                           "invalid numeric suffix '%s'"), buf);
                return (-1);
        }
 
@@ -1313,8 +1314,9 @@ str2shift(libzfs_handle_t *hdl, const char *buf)
               buf[3] == '\0'))))
                return (10*i);
 
-       zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
-           "invalid numeric suffix '%s'"), buf);
+       if (hdl)
+               zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
+                   "invalid numeric suffix '%s'"), buf);
        return (-1);
 }