]> granicus.if.org Git - zfs/commitdiff
Prevent zpool_find_vdev() from truncating vdev path
authorBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 5 Feb 2016 23:41:22 +0000 (18:41 -0500)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 8 Feb 2016 17:37:55 +0000 (09:37 -0800)
When extracting tokens from the string strtok(2) is allowed to modify
the passed buffer.  Therefore the zfs_strcmp_pathname() function must
make a copy of the passed string before passing it to strtok(3).

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Don Brady <don.brady@intel.com>
Closes #4312

lib/libzfs/libzfs_util.c

index fa55fd3a634bdb3565f11a376d0c82af3b816a3c..65b04c59ac9609d36c0d6f418206173010a0ff47 100644 (file)
@@ -1029,16 +1029,18 @@ zfs_strcmp_pathname(char *name, char *cmp, int wholedisk)
        int path_len, cmp_len;
        char path_name[MAXPATHLEN];
        char cmp_name[MAXPATHLEN];
-       char *dir;
+       char *dir, *dup;
 
        /* Strip redundant slashes if one exists due to ZPOOL_IMPORT_PATH */
        memset(cmp_name, 0, MAXPATHLEN);
-       dir = strtok(cmp, "/");
+       dup = strdup(cmp);
+       dir = strtok(dup, "/");
        while (dir) {
                strcat(cmp_name, "/");
                strcat(cmp_name, dir);
                dir = strtok(NULL, "/");
        }
+       free(dup);
 
        if (name[0] != '/')
                return (zfs_strcmp_shortname(name, cmp_name, wholedisk));