From f1ca59b81b20b17827c1ce5425f7da0e45a002af Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 7 Jun 2021 13:10:30 -0700 Subject: [PATCH] s3: smbd: Make open_file() fail early for an existing directory we are trying to open. Makes sure we keep the pathref fd open for the NT_FILE_IS_A_DIRECTORY case. Signed-off-by: Jeremy Allison Signed-off-by: Noel Power Reviewed-by: Ralph Boehme --- source3/smbd/open.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index ab89ee78884..ed180efa1e3 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1310,6 +1310,14 @@ static NTSTATUS open_file(files_struct *fsp, bool truncating = (flags & O_TRUNC); bool open_fd = false; + /* + * Catch early an attempt to open an existing + * directory as a file. + */ + if (file_existed && S_ISDIR(fsp->fsp_name->st.st_ex_mode)) { + return NT_STATUS_FILE_IS_A_DIRECTORY; + } + /* Check permissions */ /* -- 2.47.3