From: Shachar Sharon Date: Tue, 30 Jul 2024 14:36:09 +0000 (+0300) Subject: vfs_ceph_new: handle errno properly for 'readdir' X-Git-Tag: tdb-1.4.13~1397 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aa043a5808b73fc272de585c1446372fa3f21d08;p=thirdparty%2Fsamba.git vfs_ceph_new: handle errno properly for 'readdir' Take special care for readdir errno setting: in case of error, update errno by libcephfs (and protect from possible over-write by debug logging); in the case of successful result or end-of-stream restore errno to its previous value before calling the readdir_fn VFS hook. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15686 Signed-off-by: Shachar Sharon Reviewed-by: Guenther Deschner Reviewed-by: Anoop C S Autobuild-User(master): Günther Deschner Autobuild-Date(master): Wed Aug 7 14:20:02 UTC 2024 on atb-devel-224 --- diff --git a/source3/modules/vfs_ceph_new.c b/source3/modules/vfs_ceph_new.c index c11f5f24616..cf7e6b121db 100644 --- a/source3/modules/vfs_ceph_new.c +++ b/source3/modules/vfs_ceph_new.c @@ -1482,19 +1482,20 @@ static struct dirent *vfs_ceph_readdir(struct vfs_handle_struct *handle, { const struct vfs_ceph_fh *dircfh = (const struct vfs_ceph_fh *)dirp; struct dirent *result = NULL; - int errval = 0; + int saved_errno = errno; DBG_DEBUG("[CEPH] readdir(%p, %p)\n", handle, dirp); + errno = 0; result = vfs_ceph_ll_readdir(handle, dircfh); - errval = errno; - if ((result == NULL) && (errval != 0)) { - DBG_DEBUG("[CEPH] readdir(...) = %d\n", errval); + if ((result == NULL) && (errno != 0)) { + saved_errno = errno; + DBG_DEBUG("[CEPH] readdir(...) = %d\n", errno); } else { DBG_DEBUG("[CEPH] readdir(...) = %p\n", result); } - /* re-assign errno to avoid possible over-write by DBG_DEBUG */ - errno = errval; + + errno = saved_errno; return result; }