From 71974946be7efbb7f266416022df0e7acde2aa44 Mon Sep 17 00:00:00 2001 From: Chunwei Chen Date: Fri, 20 Jan 2023 11:49:56 -0800 Subject: [PATCH] Fix reading uninitialized variable in receive_read When zfs_file_read returns error, resid may be uninitialized. Reviewed-by: Brian Behlendorf Reviewed-by: Richard Yao Signed-off-by: Chunwei Chen Closes #14404 --- module/zfs/dmu_recv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/zfs/dmu_recv.c b/module/zfs/dmu_recv.c index 339fb149a..9461643ce 100644 --- a/module/zfs/dmu_recv.c +++ b/module/zfs/dmu_recv.c @@ -1500,11 +1500,11 @@ receive_read(dmu_recv_cookie_t *drc, int len, void *buf) (drc->drc_featureflags & DMU_BACKUP_FEATURE_RAW) != 0); while (done < len) { - ssize_t resid; + ssize_t resid = len - done; zfs_file_t *fp = drc->drc_fp; int err = zfs_file_read(fp, (char *)buf + done, len - done, &resid); - if (resid == len - done) { + if (err == 0 && resid == len - done) { /* * Note: ECKSUM or ZFS_ERR_STREAM_TRUNCATED indicates * that the receive was interrupted and can