From: наб Date: Tue, 6 Apr 2021 19:25:53 +0000 (+0200) Subject: libzutil: zfs_isnumber(): return false if input empty X-Git-Tag: zfs-2.2.0~2142 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=61b50107a58a1da9d86f5f81dc35d039ca629aae;p=mirror_zfs.git libzutil: zfs_isnumber(): return false if input empty zpool list, which is the only user, would mistakenly try to parse the empty string as the interval in this case: $ zpool list "a" cannot open 'a': no such pool $ zpool list "" interval cannot be zero usage: which is now symmetric with zpool get: $ zpool list "" cannot open '': name must begin with a letter Avoid breaking the "interval cannot be zero" string. There simply isn't a need for this, and it's user-facing. Reviewed-by: Brian Behlendorf Reviewed-by: Ryan Moeller Signed-off-by: Ahelenia Ziemiańska Closes #11841 Closes #11843 --- diff --git a/cmd/zpool/zpool_main.c b/cmd/zpool/zpool_main.c index 7a15c78d1..81bbf1375 100644 --- a/cmd/zpool/zpool_main.c +++ b/cmd/zpool/zpool_main.c @@ -4965,8 +4965,8 @@ get_interval_count(int *argcp, char **argv, float *iv, if (*end == '\0' && errno == 0) { if (interval == 0) { - (void) fprintf(stderr, gettext("interval " - "cannot be zero\n")); + (void) fprintf(stderr, gettext( + "interval cannot be zero\n")); usage(B_FALSE); } /* @@ -4996,8 +4996,8 @@ get_interval_count(int *argcp, char **argv, float *iv, if (*end == '\0' && errno == 0) { if (interval == 0) { - (void) fprintf(stderr, gettext("interval " - "cannot be zero\n")); + (void) fprintf(stderr, gettext( + "interval cannot be zero\n")); usage(B_FALSE); } diff --git a/lib/libzutil/zutil_nicenum.c b/lib/libzutil/zutil_nicenum.c index 306cec3ca..1a19db0df 100644 --- a/lib/libzutil/zutil_nicenum.c +++ b/lib/libzutil/zutil_nicenum.c @@ -35,6 +35,9 @@ boolean_t zfs_isnumber(const char *str) { + if (!*str) + return (B_FALSE); + for (; *str; str++) if (!(isdigit(*str) || (*str == '.'))) return (B_FALSE);