Prevent zpool_find_vdev() from truncating vdev path

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
This commit is contained in:
Brian Behlendorf 2016-02-05 18:41:22 -05:00
parent 83a5c8541e
commit b145e23daf
1 changed files with 4 additions and 2 deletions

View File

@ -1024,16 +1024,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));