]> git.proxmox.com Git - mirror_zfs.git/commitdiff
discover_cached_paths() should not corrupt nvlist string value
authorRichard Yao <richard.yao@alumni.stonybrook.edu>
Sun, 12 Mar 2023 16:30:21 +0000 (12:30 -0400)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 14 Mar 2023 22:25:45 +0000 (15:25 -0700)
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 <milky-zfs@mcmilk.de>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
Closes #14612

lib/libzutil/zutil_import.c

index 5d7b4a946c1eb60b4395f47cbcff2f82d9c2706e..7c86054f05b56ba2e564bfbad197a48709c0cf41 100644 (file)
@@ -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);
 }