Skip to content

Commit

Permalink
libzutil: zfs_isnumber(): return false if input empty
Browse files Browse the repository at this point in the history
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: <usage string follows>
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 <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #11841 
Closes #11843
  • Loading branch information
nabijaczleweli authored and behlendorf committed May 20, 2021
1 parent cfa7211 commit e24b2a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4915,8 +4915,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);
}
/*
Expand Down Expand Up @@ -4946,8 +4946,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);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/libzutil/zutil_nicenum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e24b2a2

Please sign in to comment.