zpool_valid_proplist() should not corrupt nvpair name string on error

The strings returned from parsing nvlists should be immutable, but to
simplify the code when we want a substring from it, we sometimes will
write a NULL into it and then restore the value afterward. Provided
there is no concurrent access, this is okay, unless we forget to restore
the value afterward. This was caught when constifying string functions
related to nvlists.

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
This commit is contained in:
Richard Yao 2023-03-11 15:25:04 -05:00 committed by Brian Behlendorf
parent 27ff18cd43
commit 47a7062772
1 changed files with 1 additions and 0 deletions

View File

@ -694,6 +694,7 @@ zpool_valid_proplist(libzfs_handle_t *hdl, const char *poolname,
if (strval[0] != '\0' &&
(stat64(strval, &statbuf) != 0 ||
!S_ISDIR(statbuf.st_mode))) {
*slash = '/';
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"'%s' is not a valid directory"),
strval);