cifs: skip extra NULL byte in filenames
[platform/kernel/linux-starfive.git] / fs / cifs / smb2pdu.c
index 91cfc5b..128e44e 100644 (file)
@@ -2572,19 +2572,15 @@ alloc_path_with_tree_prefix(__le16 **out_path, int *out_size, int *out_len,
 
        path_len = UniStrnlen((wchar_t *)path, PATH_MAX);
 
-       /*
-        * make room for one path separator between the treename and
-        * path
-        */
-       *out_len = treename_len + 1 + path_len;
+       /* make room for one path separator only if @path isn't empty */
+       *out_len = treename_len + (path[0] ? 1 : 0) + path_len;
 
        /*
-        * final path needs to be null-terminated UTF16 with a
-        * size aligned to 8
+        * final path needs to be 8-byte aligned as specified in
+        * MS-SMB2 2.2.13 SMB2 CREATE Request.
         */
-
-       *out_size = roundup((*out_len+1)*2, 8);
-       *out_path = kzalloc(*out_size, GFP_KERNEL);
+       *out_size = roundup(*out_len * sizeof(__le16), 8);
+       *out_path = kzalloc(*out_size + sizeof(__le16) /* null */, GFP_KERNEL);
        if (!*out_path)
                return -ENOMEM;