Skip to content

Commit 5f73bbb

Browse files
ryaobehlendorf
authored andcommitted
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 <szuberskidamian@gmail.com> Reviewed-by: Alexander Motin <mav@FreeBSD.org> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu> Closes openzfs#14264
1 parent 242a5b7 commit 5f73bbb

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/libzfs/libzfs_dataset.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ zfs_open(libzfs_handle_t *hdl, const char *path, int types)
690690
*/
691691
if (!zfs_validate_name(hdl, path, types, B_FALSE)) {
692692
(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf);
693+
errno = EINVAL;
693694
return (NULL);
694695
}
695696

@@ -737,6 +738,7 @@ zfs_open(libzfs_handle_t *hdl, const char *path, int types)
737738
&cb_data) == 0) && (cb_data.zhp == NULL)) {
738739
(void) zfs_error(hdl, EZFS_NOENT, errbuf);
739740
zfs_close(pzhp);
741+
errno = ENOENT;
740742
return (NULL);
741743
}
742744
if (cb_data.zhp == NULL) {
@@ -755,6 +757,7 @@ zfs_open(libzfs_handle_t *hdl, const char *path, int types)
755757
if (!(types & zhp->zfs_type)) {
756758
(void) zfs_error(hdl, EZFS_BADTYPE, errbuf);
757759
zfs_close(zhp);
760+
errno = EINVAL;
758761
return (NULL);
759762
}
760763

lib/libzfs/libzfs_sendrecv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ dump_filesystem(zfs_handle_t *zhp, send_dump_data_t *sdd)
12891289
if (snap != NULL)
12901290
rv = dump_snapshot(snap, sdd);
12911291
else
1292-
rv = -1;
1292+
rv = errno;
12931293
}
12941294

12951295
/* Dump tosnap. */
@@ -1301,7 +1301,7 @@ dump_filesystem(zfs_handle_t *zhp, send_dump_data_t *sdd)
13011301
if (snap != NULL)
13021302
rv = dump_snapshot(snap, sdd);
13031303
else
1304-
rv = -1;
1304+
rv = errno;
13051305
}
13061306
}
13071307

0 commit comments

Comments
 (0)