]> git.proxmox.com Git - mirror_zfs.git/commitdiff
libzutil: zfs_isnumber(): return false if input empty
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Tue, 6 Apr 2021 19:25:53 +0000 (21:25 +0200)
committerGitHub <noreply@github.com>
Tue, 6 Apr 2021 19:25:53 +0000 (12:25 -0700)
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

cmd/zpool/zpool_main.c
lib/libzutil/zutil_nicenum.c

index 7a15c78d10bbc6d8baf1df0c3a25aa7bd11382e6..81bbf1375d0cd5e5805fd080d9f517d8543d3505 100644 (file)
@@ -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);
                        }
 
index 306cec3caddf50da282f1ce76cf96ade39cb06e2..1a19db0dfebc9ed8b1bdf12908511df9e079d411 100644 (file)
@@ -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);