Commit c9434069518d74c16a9298d20fb927be8ab259f0

Authored by Steve French
Committed by Greg Kroah-Hartman
1 parent 2545a404c7

CIFS: fix mount failure with broken pathnames when smb3 mount with mapchars option

commit ce36d9ab3bab06b7b5522f5c8b68fac231b76ffb upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 4 additions and 3 deletions Side-by-side Diff

fs/cifs/cifs_unicode.c
... ... @@ -290,7 +290,8 @@
290 290 cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
291 291 const struct nls_table *cp, int mapChars)
292 292 {
293   - int i, j, charlen;
  293 + int i, charlen;
  294 + int j = 0;
294 295 char src_char;
295 296 __le16 dst_char;
296 297 wchar_t tmp;
297 298  
... ... @@ -298,12 +299,11 @@
298 299 if (!mapChars)
299 300 return cifs_strtoUTF16(target, source, PATH_MAX, cp);
300 301  
301   - for (i = 0, j = 0; i < srclen; j++) {
  302 + for (i = 0; i < srclen; j++) {
302 303 src_char = source[i];
303 304 charlen = 1;
304 305 switch (src_char) {
305 306 case 0:
306   - put_unaligned(0, &target[j]);
307 307 goto ctoUTF16_out;
308 308 case ':':
309 309 dst_char = cpu_to_le16(UNI_COLON);
... ... @@ -350,6 +350,7 @@
350 350 }
351 351  
352 352 ctoUTF16_out:
  353 + put_unaligned(0, &target[j]); /* Null terminate target unicode string */
353 354 return j;
354 355 }
355 356