From 4a540d68b773637af92f266afc61cdd6d7b41223 Mon Sep 17 00:00:00 2001 From: Rich Ercolani <214141+rincebrain@users.noreply.github.com> Date: Mon, 4 Oct 2021 13:17:30 -0400 Subject: [PATCH] Reject zfs send -RI with nonexistent fromsnap Right now, zfs send -I dataset@nonexistent dataset@existent fails, but zfs send -RI dataset@nonexistent dataset@existent does not. Reviewed-by: Brian Behlendorf Signed-off-by: Rich Ercolani Closes #12574 Closes #12575 --- lib/libzfs/libzfs_sendrecv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index ca99db911f75..812d883408a2 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -2175,6 +2175,23 @@ zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, return (zfs_error(zhp->zfs_hdl, EZFS_NOENT, errbuf)); } + if (fromsnap) { + char full_fromsnap_name[ZFS_MAX_DATASET_NAME_LEN]; + if (snprintf(full_fromsnap_name, sizeof (full_fromsnap_name), + "%s@%s", zhp->zfs_name, fromsnap) >= + sizeof (full_fromsnap_name)) { + err = EINVAL; + goto stderr_out; + } + zfs_handle_t *fromsnapn = zfs_open(zhp->zfs_hdl, + full_fromsnap_name, ZFS_TYPE_SNAPSHOT); + if (fromsnapn == NULL) { + err = -1; + goto err_out; + } + zfs_close(fromsnapn); + } + if (flags->replicate || flags->doall || flags->props || flags->holds || flags->backup) { char full_tosnap_name[ZFS_MAX_DATASET_NAME_LEN];