From 6555fa9d8fbc7f7be39f5ffc3a31ef14af92779c Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 21 May 2019 13:36:45 +0000 Subject: [PATCH] s3/smbd: cppcheck: Fix ctunullpointer error Fixes: source3/smbd/files.c:783: error: ctunullpointer: Null pointer dereference: buf <--[cppcheck] Signed-off-by: Noel Power Reviewed-by: Andreas Schneider --- source3/smbd/files.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 99b4937c99b..46fc4191950 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -778,7 +778,18 @@ const struct GUID *fsp_client_guid(const files_struct *fsp) size_t fsp_fullbasepath(struct files_struct *fsp, char *buf, size_t buflen) { - int len; + 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 fullbasepatch (without + * needing to allocate or write to buf) + */ + if (buf == NULL) { + buf = tmp_buf; + } len = snprintf(buf, buflen, "%s/%s", fsp->conn->connectpath, fsp->fsp_name->base_name); -- 2.47.3