diff options
author | Brian Behlendorf <[email protected]> | 2016-02-05 18:41:22 -0500 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2016-03-22 17:54:07 -0700 |
commit | b145e23dafbabf0fefc432704635386a9f66df5c (patch) | |
tree | 92be0ceb7cb1b54f70407b394be9da06859052ef /lib | |
parent | 83a5c8541e281866a11d3753e4a3f81051084651 (diff) |
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 <[email protected]>
Signed-off-by: Don Brady <[email protected]>
Closes #4312
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libzfs/libzfs_util.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 678eeadc0..ccace2d20 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -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)); |