]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph_new: proper failure-handling in chdir and getwd
authorShachar Sharon <ssharon@redhat.com>
Wed, 3 Dec 2025 09:39:51 +0000 (11:39 +0200)
committerAnoop C S <anoopcs@samba.org>
Thu, 4 Dec 2025 10:02:55 +0000 (10:02 +0000)
In case of an unlikely failure of SMB_VFS_HANDLE_GET_DATA macro, bail
out using 'goto' in order to ensure that START_PROFILE_X is properly
matched by END_PROFILE_X.

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
Reviewed-by: John Mulligan <jmulligan@redhat.com>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Autobuild-User(master): Anoop C S <anoopcs@samba.org>
Autobuild-Date(master): Thu Dec  4 10:02:55 UTC 2025 on atb-devel-224

source3/modules/vfs_ceph_new.c

index d0f35affac7fdf75c91a1c70d6bdae203507fa5d..1ef3ca3714a5cf14ac52feb47d84c8750fb75e8e 100644 (file)
@@ -3408,16 +3408,18 @@ out:
 static int vfs_ceph_chdir(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname)
 {
-       int result = -1;
+       int result = -ENOMEM;
        struct vfs_ceph_config *config = NULL;
 
        START_PROFILE_X(SNUM(handle->conn), syscall_chdir);
+
        SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config,
-                               return -ENOMEM);
+                               goto out);
 
        DBG_DEBUG("[CEPH] chdir: handle=%p name=%s\n", handle, smb_fname->base_name);
        result = config->ceph_chdir_fn(config->mount, smb_fname->base_name);
        DBG_DEBUG("[CEPH] chdir: name=%s result=%d\n", smb_fname->base_name, result);
+out:
        END_PROFILE_X(syscall_chdir);
        return status_code(result);
 }
@@ -3427,15 +3429,18 @@ static struct smb_filename *vfs_ceph_getwd(struct vfs_handle_struct *handle,
 {
        const char *cwd = NULL;
        struct vfs_ceph_config *config = NULL;
+       struct smb_filename *result = NULL;
 
        START_PROFILE_X(SNUM(handle->conn), syscall_getwd);
        SMB_VFS_HANDLE_GET_DATA(handle, config, struct vfs_ceph_config,
-                               return NULL);
+                               goto out);
 
        cwd = config->ceph_getcwd_fn(config->mount);
        DBG_DEBUG("[CEPH] getwd: handle=%p cwd=%s\n", handle, cwd);
+       result = cp_smb_basename(ctx, cwd);
+out:
        END_PROFILE_X(syscall_getwd);
-       return cp_smb_basename(ctx, cwd);
+       return result;
 }
 
 static int strict_allocate_ftruncate(struct vfs_handle_struct *handle,