From 53c2ec1d1b3ffdc90c1c6516558e6b4da77c2446 Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Thu, 29 Nov 2012 14:56:07 +0900 Subject: [PATCH] Fix 'zpool create' segfault due to bad syntax 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 Closes #1118 --- lib/libzfs/libzfs_util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 16affd1cec..42700877a6 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -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); }