Skip to content

Commit ce36d9a

Browse files
committed
[CIFS] fix mount failure with broken pathnames when smb3 mount with mapchars option
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 <[email protected]> Cc: <[email protected]> Reviewed-by: David Disseldorp <[email protected]>
1 parent 08bc035 commit ce36d9a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/cifs/cifs_unicode.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,20 @@ int
290290
cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
291291
const struct nls_table *cp, int mapChars)
292292
{
293-
int i, j, charlen;
293+
int i, charlen;
294+
int j = 0;
294295
char src_char;
295296
__le16 dst_char;
296297
wchar_t tmp;
297298

298299
if (!mapChars)
299300
return cifs_strtoUTF16(target, source, PATH_MAX, cp);
300301

301-
for (i = 0, j = 0; i < srclen; j++) {
302+
for (i = 0; i < srclen; j++) {
302303
src_char = source[i];
303304
charlen = 1;
304305
switch (src_char) {
305306
case 0:
306-
put_unaligned(0, &target[j]);
307307
goto ctoUTF16_out;
308308
case ':':
309309
dst_char = cpu_to_le16(UNI_COLON);
@@ -350,6 +350,7 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
350350
}
351351

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

0 commit comments

Comments
 (0)