]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph_new: handle errno properly for 'readdir'
authorShachar Sharon <ssharon@redhat.com>
Tue, 30 Jul 2024 14:36:09 +0000 (17:36 +0300)
committerGünther Deschner <gd@samba.org>
Wed, 7 Aug 2024 14:20:02 +0000 (14:20 +0000)
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 <ssharon@redhat.com>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Autobuild-User(master): Günther Deschner <gd@samba.org>
Autobuild-Date(master): Wed Aug  7 14:20:02 UTC 2024 on atb-devel-224

source3/modules/vfs_ceph_new.c

index c11f5f2461654198acb5e850f90d1545dd499909..cf7e6b121db9e62d5d7fa9e4910b7cee177f36f3 100644 (file)
@@ -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;
 }