diff options
author | Richard Yao <[email protected]> | 2022-12-04 17:03:14 -0500 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2022-12-08 14:15:27 -0800 |
commit | 5f73bbba436748654bf4fd6596c9cdba1a9914f3 (patch) | |
tree | 4f58f9a003f3faca736932d70186a80d72622169 /lib | |
parent | 242a5b748cbf02001a1324f3e195df56f8f28f5a (diff) |
Do not pass -1 to strerror() from zfs_send_cb_impl()
`zfs_send_cb_impl()` calls `dump_filesystems()`, which calls
`dump_filesystem()`, which will return `-1` as an error when
`zfs_open()` returns `NULL`.
This will be passed to `zfs_standard_error()`, which passes it to
`zfs_standard_error_fmt()`, which passes it to `strerror()`.
To fix this, we modify zfs_open() to set `errno` whenever it returns
NULL. Most of the cases already have `errno` set (since they pass it to
`zfs_standard_error_fmt()`, which makes this easy. Then we modify
`dump_filesystem()` to pass `errno` instead of `-1`.
Reported-by: Coverity (CID-1524598)
Reviewed-by: Damian Szuberski <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Richard Yao <[email protected]>
Closes #14264
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libzfs/libzfs_dataset.c | 3 | ||||
-rw-r--r-- | lib/libzfs/libzfs_sendrecv.c | 4 |
2 files changed, 5 insertions, 2 deletions
diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index 87bc4ea66..fd9fbd658 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -690,6 +690,7 @@ zfs_open(libzfs_handle_t *hdl, const char *path, int types) */ if (!zfs_validate_name(hdl, path, types, B_FALSE)) { (void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf); + errno = EINVAL; return (NULL); } @@ -737,6 +738,7 @@ zfs_open(libzfs_handle_t *hdl, const char *path, int types) &cb_data) == 0) && (cb_data.zhp == NULL)) { (void) zfs_error(hdl, EZFS_NOENT, errbuf); zfs_close(pzhp); + errno = ENOENT; return (NULL); } if (cb_data.zhp == NULL) { @@ -755,6 +757,7 @@ zfs_open(libzfs_handle_t *hdl, const char *path, int types) if (!(types & zhp->zfs_type)) { (void) zfs_error(hdl, EZFS_BADTYPE, errbuf); zfs_close(zhp); + errno = EINVAL; return (NULL); } diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index b53acdcea..089d46b13 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -1289,7 +1289,7 @@ dump_filesystem(zfs_handle_t *zhp, send_dump_data_t *sdd) if (snap != NULL) rv = dump_snapshot(snap, sdd); else - rv = -1; + rv = errno; } /* Dump tosnap. */ @@ -1301,7 +1301,7 @@ dump_filesystem(zfs_handle_t *zhp, send_dump_data_t *sdd) if (snap != NULL) rv = dump_snapshot(snap, sdd); else - rv = -1; + rv = errno; } } |