From 193df617816127a75bc4a29b46d3ada920c52f76 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 29 Oct 2023 12:10:08 +0100 Subject: [PATCH] smbd: Simplify fsp_fullbasepath() Don't call snprintf() if not necessary. Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- source3/smbd/files.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 0c54ca37468..15cc7d82be1 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -2268,17 +2268,10 @@ NTSTATUS fsp_set_smb_fname(struct files_struct *fsp, size_t fsp_fullbasepath(struct files_struct *fsp, char *buf, size_t buflen) { int len = 0; - char tmp_buf[1] = {'\0'}; - /* - * Don't pass NULL buffer to snprintf (to satisfy static checker) - * Some callers will call this function with NULL for buf and - * 0 for buflen in order to get length of fullbasepath (without - * needing to allocate or write to buf) - */ - if (buf == NULL) { - buf = tmp_buf; - SMB_ASSERT(buflen==0); + if ((buf == NULL) || (buflen == 0)) { + return strlen(fsp->conn->connectpath) + 1 + + strlen(fsp->fsp_name->base_name); } len = snprintf(buf, buflen, "%s/%s", fsp->conn->connectpath, -- 2.11.4.GIT