]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
vfs_ceph: use talloc in realpath hook
authorShachar Sharon <ssharon@redhat.com>
Wed, 22 May 2024 13:28:32 +0000 (16:28 +0300)
committerAnoop C S <anoopcs@samba.org>
Thu, 27 Jun 2024 05:34:33 +0000 (05:34 +0000)
Prefer talloc_asprintf over asprintf when resolving realpath.
Re-format code using 'git clang-format'.

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/modules/vfs_ceph.c

index 6c96d27dccc94f3029ff0c037c1a30c0cd7227fc..c81a7d2d99cfaff2c02cac613e39d75e86367f31 100644 (file)
@@ -1513,27 +1513,26 @@ static struct smb_filename *cephwrap_realpath(struct vfs_handle_struct *handle,
        const char *path = smb_fname->base_name;
        size_t len = strlen(path);
        struct smb_filename *result_fname = NULL;
-       int r = -1;
 
-       if (len && (path[0] == '/')) {
-               r = asprintf(&result, "%s", path);
+       if (path[0] == '/') {
+               result = talloc_strdup(ctx, path);
        } else if ((len >= 2) && (path[0] == '.') && (path[1] == '/')) {
                if (len == 2) {
-                       r = asprintf(&result, "%s", cwd);
+                       result = talloc_strdup(ctx, cwd);
                } else {
-                       r = asprintf(&result, "%s/%s", cwd, &path[2]);
+                       result = talloc_asprintf(ctx, "%s/%s", cwd, &path[2]);
                }
        } else {
-               r = asprintf(&result, "%s/%s", cwd, path);
+               result = talloc_asprintf(ctx, "%s/%s", cwd, path);
        }
 
-       if (r < 0) {
+       if (result == NULL) {
                return NULL;
        }
 
        DBG_DEBUG("[CEPH] realpath(%p, %s) = %s\n", handle, path, result);
        result_fname = synthetic_smb_fname(ctx, result, NULL, NULL, 0, 0);
-       SAFE_FREE(result);
+       TALLOC_FREE(result);
        return result_fname;
 }