libzutil: zfs_strcmp_pathname: don't allocate, remove strtok

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12094
This commit is contained in:
наб 2021-05-20 22:45:08 +02:00 committed by Brian Behlendorf
parent a0cb347cea
commit 2fdd61a30b
1 changed files with 7 additions and 8 deletions

View File

@ -141,18 +141,17 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk)
int path_len, cmp_len;
char path_name[MAXPATHLEN];
char cmp_name[MAXPATHLEN];
char *dir, *dup;
char *dir, *tmp = NULL;
/* Strip redundant slashes if one exists due to ZPOOL_IMPORT_PATH */
memset(cmp_name, 0, MAXPATHLEN);
dup = strdup(cmp);
dir = strtok(dup, "/");
while (dir) {
/* Strip redundant slashes if they exist due to ZPOOL_IMPORT_PATH */
cmp_name[0] = '\0';
(void) strlcpy(path_name, cmp, sizeof (path_name));
for (dir = strtok_r(path_name, "/", &tmp);
dir != NULL;
dir = strtok_r(NULL, "/", &tmp)) {
strlcat(cmp_name, "/", sizeof (cmp_name));
strlcat(cmp_name, dir, sizeof (cmp_name));
dir = strtok(NULL, "/");
}
free(dup);
if (name[0] != '/')
return (zfs_strcmp_shortname(name, cmp_name, wholedisk));