Skip to content

Commit

Permalink
Prevent zpool_find_vdev() from truncating vdev path
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Don Brady <[email protected]>
Closes #4312
behlendorf committed Feb 8, 2016
1 parent 6b42ea8 commit eea9309
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/libzfs/libzfs_util.c
Original file line number Diff line number Diff line change
@@ -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));

0 comments on commit eea9309

Please sign in to comment.