]> granicus.if.org Git - zfs/commitdiff
Prevent pointer to an out-of-scope local variable
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Fri, 21 Jun 2019 01:31:53 +0000 (10:31 +0900)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 21 Jun 2019 01:31:52 +0000 (18:31 -0700)
`show_str` could be a pointer to a local variable in stack
which is out-of-scope by the time
`return (snprintf(buf, buflen, "%s\n", show_str));`
is called.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Closes #8924
Closes #8940

module/zfs/zfs_sysfs.c

index 2f5bea9aa9966789841ceffec2bb1501d708df8e..bb7f3b69a6620a5d9d23028f596fcfac9eaed887 100644 (file)
@@ -264,6 +264,7 @@ zprop_sysfs_show(const char *attr_name, const zprop_desc_t *property,
     char *buf, size_t buflen)
 {
        const char *show_str;
+       char number[32];
 
        /* For dataset properties list the dataset types that apply */
        if (strcmp(attr_name, "datasets") == 0 &&
@@ -291,8 +292,6 @@ zprop_sysfs_show(const char *attr_name, const zprop_desc_t *property,
        } else if (strcmp(attr_name, "values") == 0) {
                show_str = property->pd_values ? property->pd_values : "";
        } else if (strcmp(attr_name, "default") == 0) {
-               char number[32];
-
                switch (property->pd_proptype) {
                case PROP_TYPE_NUMBER:
                        (void) snprintf(number, sizeof (number), "%llu",