]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Simplify fsp_fullbasepath()
authorVolker Lendecke <vl@samba.org>
Sun, 4 Feb 2024 09:57:28 +0000 (10:57 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 12 Mar 2024 13:31:31 +0000 (13:31 +0000)
snprintf deals well with NULL/0 buffers. Basically this undoes
6555fa9d8fbc and 193df6176555fa9d8fbc gave cppcheck as a reason for
this patch, but if I look into susv4's snprintf definition I find:

If n is zero, nothing shall be written and s may be a null pointer.

This removes the checks and makes sure we fulfill the requirement of
susv4 that states that buf can only be NULL if buflen is 0.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/smbd/files.c

index 6aad76a8a5c41f7d3bcf612beb15ce0882b55c33..ef1eb1a78a82a14f6082280579885e60af3969f7 100644 (file)
@@ -2574,9 +2574,11 @@ size_t fsp_fullbasepath(struct files_struct *fsp, char *buf, size_t buflen)
 {
        int len = 0;
 
-       if ((buf == NULL) || (buflen == 0)) {
-               return strlen(fsp->conn->connectpath) + 1 +
-                      strlen(fsp->fsp_name->base_name);
+       if (buf == NULL) {
+               /*
+                * susv4 allows buf==NULL if buflen==0 for snprintf.
+                */
+               SMB_ASSERT(buflen == 0);
        }
 
        len = snprintf(buf, buflen, "%s/%s", fsp->conn->connectpath,