]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Fix the turning an absolute symlink into a relative one
authorVolker Lendecke <vl@samba.org>
Sun, 4 Feb 2024 10:45:22 +0000 (11:45 +0100)
committerRalph Boehme <slow@samba.org>
Fri, 22 Nov 2024 09:50:37 +0000 (09:50 +0000)
If dirfsp is the share root, we end up with a "/." at the end of
subdir_path. subdir_of() does not cover that case. fsp_fullbasepath()
takes care of that case and also avoids a talloc.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/files.c

index 8e2a39941ce815623dc16422a21f7b7678d3c04e..2a76e2bcc53a4aaaa65abedf5e163919152d6350 100644 (file)
@@ -808,18 +808,13 @@ NTSTATUS read_symlink_reparse(TALLOC_CTX *mem_ctx,
        }
 
        if (lnk->substitute_name[0] == '/') {
-               char *subdir_path = NULL;
+               size_t len = fsp_fullbasepath(dirfsp, NULL, 0);
+               char subdir_path[len + 1];
                char *abs_target_canon = NULL;
                const char *relative = NULL;
                bool in_share;
 
-               subdir_path = talloc_asprintf(talloc_tos(),
-                                             "%s/%s",
-                                             dirfsp->conn->connectpath,
-                                             dirfsp->fsp_name->base_name);
-               if (subdir_path == NULL) {
-                       goto nomem;
-               }
+               fsp_fullbasepath(dirfsp, subdir_path, sizeof(subdir_path));
 
                abs_target_canon = canonicalize_absolute_path(
                        talloc_tos(), lnk->substitute_name);
@@ -828,7 +823,7 @@ NTSTATUS read_symlink_reparse(TALLOC_CTX *mem_ctx,
                }
 
                in_share = subdir_of(subdir_path,
-                                    strlen(subdir_path),
+                                    len,
                                     abs_target_canon,
                                     &relative);
                if (in_share) {