diff mbox

[CIFS] fix SMB3 mount failure due to corrupted empty paths when mapchars option used

Message ID CAH2r5mtX=ZyPm4JO7WH9uDo3nE_T4GP9h822EP8Ch=sbp2H1vA@mail.gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Steve French June 23, 2014, 1:49 a.m. UTC
When we SMB3 mounted with mapchars (to allow reserved characters : \ / > < * ?
via the Unicode Windows to POSIX remap range) empty paths
(eg when we open "" to query the root of the SMB3 directory on mount) were not
null terminated so we sent garbarge as a path name on empty paths which caused
SMB2/SMB2.1/SMB3 mounts to fail when mapchars was specified.  mapchars is
particularly important since Unix Extensions for SMB3 are not supported (yet)

Signed-off-by: Steve French <smfrench@gmail.com>
---
 fs/cifs/cifs_unicode.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

             dst_char = cpu_to_le16(UNI_COLON);
@@ -350,6 +350,7 @@ cifsConvertToUTF16(__le16 *target, const char
*source, int srclen,
     }

 ctoUTF16_out:
+    put_unaligned(0, &target[j]); /* Null terminate target unicode string */
     return j;
 }

Comments

David Disseldorp June 24, 2014, 11:07 a.m. UTC | #1
Looks good Steve.

On Sun, 22 Jun 2014 20:49:57 -0500, Steve French wrote:

> When we SMB3 mounted with mapchars (to allow reserved characters : \ / > < * ?
> via the Unicode Windows to POSIX remap range) empty paths
> (eg when we open "" to query the root of the SMB3 directory on mount) were not
> null terminated so we sent garbarge as a path name on empty paths which caused
> SMB2/SMB2.1/SMB3 mounts to fail when mapchars was specified.  mapchars is
> particularly important since Unix Extensions for SMB3 are not supported (yet)
> 
> Signed-off-by: Steve French <smfrench@gmail.com>

Reviewed-by: David Disseldorp <ddiss@suse.de>
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index 0227b45..15e9505 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -290,7 +290,8 @@  int
 cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
          const struct nls_table *cp, int mapChars)
 {
-    int i, j, charlen;
+    int i, charlen;
+    int j = 0;
     char src_char;
     __le16 dst_char;
     wchar_t tmp;
@@ -298,12 +299,11 @@  cifsConvertToUTF16(__le16 *target, const char
*source, int srclen,
     if (!mapChars)
         return cifs_strtoUTF16(target, source, PATH_MAX, cp);

-    for (i = 0, j = 0; i < srclen; j++) {
+    for (i = 0; i < srclen; j++) {
         src_char = source[i];
         charlen = 1;
         switch (src_char) {
         case 0:
-            put_unaligned(0, &target[j]);
             goto ctoUTF16_out;
         case ':':