diff options
author | Richard Yao <[email protected]> | 2023-03-12 12:30:21 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2023-03-14 15:25:45 -0700 |
commit | 50f6934b9c1f4aa583592e8a969b934440a44c64 (patch) | |
tree | 61ef272153282654eb574fd73e7d440207802bab /lib | |
parent | 47a7062772766c8a532df157a7be681327c20ea6 (diff) |
discover_cached_paths() should not corrupt nvlist string value
discover_cached_paths() will write a NULL into a string from a nvlist to
use it as a substring, but does not restore it before return. This
corrupts the nvlist. It should be harmless unless the string is needed
again later, but we should not do this, so let us fix it.
Reviewed-by: Tino Reichardt <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Richard Yao <[email protected]>
Closes #14612
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libzutil/zutil_import.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/libzutil/zutil_import.c b/lib/libzutil/zutil_import.c index 5d7b4a946..7c86054f0 100644 --- a/lib/libzutil/zutil_import.c +++ b/lib/libzutil/zutil_import.c @@ -1564,12 +1564,19 @@ discover_cached_paths(libpc_handle_t *hdl, nvlist_t *nv, * our directory cache. */ if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0) { - if ((dl = zfs_dirnamelen(path)) == -1) + int ret; + char c = '\0'; + if ((dl = zfs_dirnamelen(path)) == -1) { path = (char *)"."; - else + } else { + c = path[dl]; path[dl] = '\0'; - return (zpool_find_import_scan_dir(hdl, lock, cache, - path, 0)); + } + ret = zpool_find_import_scan_dir(hdl, lock, cache, + path, 0); + if (c != '\0') + path[dl] = c; + return (ret); } return (0); } |