Skip to content

Commit

Permalink
libzutil: zfs_resolve_shortname: don't strdup() ZPOOL_IMPORT_PATH
Browse files Browse the repository at this point in the history
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes openzfs#13223
  • Loading branch information
nabijaczleweli authored and andrewc12 committed Sep 23, 2022
1 parent b025e1b commit 1e6ce64
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions lib/libzutil/zutil_device_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,41 +56,41 @@ zfs_dirnamelen(const char *path)
int
zfs_resolve_shortname(const char *name, char *path, size_t len)
{
int i, error = -1;
char *dir, *env, *envdup, *tmp = NULL;

env = getenv("ZPOOL_IMPORT_PATH");
errno = ENOENT;
const char *env = getenv("ZPOOL_IMPORT_PATH");

if (env) {
envdup = strdup(env);
for (dir = strtok_r(envdup, ":", &tmp);
dir != NULL && error != 0;
dir = strtok_r(NULL, ":", &tmp)) {
(void) snprintf(path, len, "%s/%s", dir, name);
error = access(path, F_OK);
for (;;) {
env += strspn(env, ":");
size_t dirlen = strcspn(env, ":");
if (dirlen) {
(void) snprintf(path, len, "%.*s/%s",
(int)dirlen, env, name);
if (access(path, F_OK) == 0)
return (0);

env += dirlen;
} else
break;
}
free(envdup);
} else {
const char * const *zpool_default_import_path;
size_t count;
const char *const *zpool_default_import_path =
zpool_default_search_paths(&count);

zpool_default_import_path = zpool_default_search_paths(&count);

for (i = 0; i < count && error < 0; i++) {
for (size_t i = 0; i < count; ++i) {
(void) snprintf(path, len, "%s/%s",
zpool_default_import_path[i], name);
error = access(path, F_OK);
if (access(path, F_OK) == 0)
return (0);
}
}

#ifdef _WIN32
// Nothing found, attempt OS specific shortnames
if (error)
error = zfs_resolve_shortname_os(name, path, len);
/* Nothing found, attempt OS specific shortnames */
if (zfs_resolve_shortname_os(name, path, len) == 0)
return (0);
#endif

return (error ? ENOENT : 0);
return (ENOENT);
}

/*
Expand All @@ -106,7 +106,7 @@ zfs_strcmp_shortname(const char *name, const char *cmp_name, int wholedisk)
int path_len, cmp_len, i = 0, error = ENOENT;
char *dir, *env, *envdup = NULL, *tmp = NULL;
char path_name[MAXPATHLEN];
const char * const *zpool_default_import_path = NULL;
const char *const *zpool_default_import_path = NULL;
size_t count;

cmp_len = strlen(cmp_name);
Expand Down

0 comments on commit 1e6ce64

Please sign in to comment.