From 2fdd61a30b517498f766b5a7d9eec6182c32cd72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 20 May 2021 22:45:08 +0200 Subject: [PATCH] libzutil: zfs_strcmp_pathname: don't allocate, remove strtok MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Brian Behlendorf Reviewed-by: John Kennedy Signed-off-by: Ahelenia ZiemiaƄska Closes #12094 --- lib/libzutil/zutil_device_path.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/libzutil/zutil_device_path.c b/lib/libzutil/zutil_device_path.c index 27ca80e504..be8d02673b 100644 --- a/lib/libzutil/zutil_device_path.c +++ b/lib/libzutil/zutil_device_path.c @@ -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));