From: Volker Lendecke Date: Sun, 4 Feb 2024 10:45:22 +0000 (+0100) Subject: smbd: Fix the turning an absolute symlink into a relative one X-Git-Tag: tdb-1.4.13~484 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0d8b71f0b6c953d031caff0c37a309646dc57c57;p=thirdparty%2Fsamba.git smbd: Fix the turning an absolute symlink into a relative one 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 Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 8e2a39941ce..2a76e2bcc53 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -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) {