Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit acbbb76a authored by Steve French's avatar Steve French
Browse files

CIFS: Rename *UCS* functions to *UTF16*



to reflect the unicode encoding used by CIFS protocol.

Signed-off-by: default avatarPavel Shilovsky <piastry@etersoft.ru>
Acked-by: default avatarJeff Layton <jlayton@samba.org>
Reviewed-by: default avatarShirish Pargaonkar <shirishpargaonkar@gmail.com>
parent c5600187
Loading
Loading
Loading
Loading
+21 −20
Original line number Original line Diff line number Diff line
@@ -27,17 +27,17 @@
#include "cifs_debug.h"
#include "cifs_debug.h"


/*
/*
 * cifs_ucs2_bytes - how long will a string be after conversion?
 * cifs_utf16_bytes - how long will a string be after conversion?
 * @ucs - pointer to input string
 * @utf16 - pointer to input string
 * @maxbytes - don't go past this many bytes of input string
 * @maxbytes - don't go past this many bytes of input string
 * @codepage - destination codepage
 * @codepage - destination codepage
 *
 *
 * Walk a ucs2le string and return the number of bytes that the string will
 * Walk a utf16le string and return the number of bytes that the string will
 * be after being converted to the given charset, not including any null
 * be after being converted to the given charset, not including any null
 * termination required. Don't walk past maxbytes in the source buffer.
 * termination required. Don't walk past maxbytes in the source buffer.
 */
 */
int
int
cifs_ucs2_bytes(const __le16 *from, int maxbytes,
cifs_utf16_bytes(const __le16 *from, int maxbytes,
		const struct nls_table *codepage)
		const struct nls_table *codepage)
{
{
	int i;
	int i;
@@ -122,7 +122,7 @@ cp_convert:
}
}


/*
/*
 * cifs_from_ucs2 - convert utf16le string to local charset
 * cifs_from_utf16 - convert utf16le string to local charset
 * @to - destination buffer
 * @to - destination buffer
 * @from - source buffer
 * @from - source buffer
 * @tolen - destination buffer size (in bytes)
 * @tolen - destination buffer size (in bytes)
@@ -130,7 +130,7 @@ cp_convert:
 * @codepage - codepage to which characters should be converted
 * @codepage - codepage to which characters should be converted
 * @mapchar - should characters be remapped according to the mapchars option?
 * @mapchar - should characters be remapped according to the mapchars option?
 *
 *
 * Convert a little-endian ucs2le string (as sent by the server) to a string
 * Convert a little-endian utf16le string (as sent by the server) to a string
 * in the provided codepage. The tolen and fromlen parameters are to ensure
 * in the provided codepage. The tolen and fromlen parameters are to ensure
 * that the code doesn't walk off of the end of the buffer (which is always
 * that the code doesn't walk off of the end of the buffer (which is always
 * a danger if the alignment of the source buffer is off). The destination
 * a danger if the alignment of the source buffer is off). The destination
@@ -139,12 +139,12 @@ cp_convert:
 * null terminator).
 * null terminator).
 *
 *
 * Note that some windows versions actually send multiword UTF-16 characters
 * Note that some windows versions actually send multiword UTF-16 characters
 * instead of straight UCS-2. The linux nls routines however aren't able to
 * instead of straight UTF16-2. The linux nls routines however aren't able to
 * deal with those characters properly. In the event that we get some of
 * deal with those characters properly. In the event that we get some of
 * those characters, they won't be translated properly.
 * those characters, they won't be translated properly.
 */
 */
int
int
cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen,
cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen,
		 const struct nls_table *codepage, bool mapchar)
		 const struct nls_table *codepage, bool mapchar)
{
{
	int i, charlen, safelen;
	int i, charlen, safelen;
@@ -190,13 +190,13 @@ cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen,
}
}


/*
/*
 * NAME:	cifs_strtoUCS()
 * NAME:	cifs_strtoUTF16()
 *
 *
 * FUNCTION:	Convert character string to unicode string
 * FUNCTION:	Convert character string to unicode string
 *
 *
 */
 */
int
int
cifs_strtoUCS(__le16 *to, const char *from, int len,
cifs_strtoUTF16(__le16 *to, const char *from, int len,
	      const struct nls_table *codepage)
	      const struct nls_table *codepage)
{
{
	int charlen;
	int charlen;
@@ -206,7 +206,7 @@ cifs_strtoUCS(__le16 *to, const char *from, int len,
	for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
	for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
		charlen = codepage->char2uni(from, len, &wchar_to);
		charlen = codepage->char2uni(from, len, &wchar_to);
		if (charlen < 1) {
		if (charlen < 1) {
			cERROR(1, "strtoUCS: char2uni of 0x%x returned %d",
			cERROR(1, "strtoUTF16: char2uni of 0x%x returned %d",
				*from, charlen);
				*from, charlen);
			/* A question mark */
			/* A question mark */
			wchar_to = 0x003f;
			wchar_to = 0x003f;
@@ -220,7 +220,8 @@ cifs_strtoUCS(__le16 *to, const char *from, int len,
}
}


/*
/*
 * cifs_strndup_from_ucs - copy a string from wire format to the local codepage
 * cifs_strndup_from_utf16 - copy a string from wire format to the local
 * codepage
 * @src - source string
 * @src - source string
 * @maxlen - don't walk past this many bytes in the source string
 * @maxlen - don't walk past this many bytes in the source string
 * @is_unicode - is this a unicode string?
 * @is_unicode - is this a unicode string?
@@ -231,19 +232,19 @@ cifs_strtoUCS(__le16 *to, const char *from, int len,
 * error.
 * error.
 */
 */
char *
char *
cifs_strndup_from_ucs(const char *src, const int maxlen, const bool is_unicode,
cifs_strndup_from_utf16(const char *src, const int maxlen,
	     const struct nls_table *codepage)
			const bool is_unicode, const struct nls_table *codepage)
{
{
	int len;
	int len;
	char *dst;
	char *dst;


	if (is_unicode) {
	if (is_unicode) {
		len = cifs_ucs2_bytes((__le16 *) src, maxlen, codepage);
		len = cifs_utf16_bytes((__le16 *) src, maxlen, codepage);
		len += nls_nullsize(codepage);
		len += nls_nullsize(codepage);
		dst = kmalloc(len, GFP_KERNEL);
		dst = kmalloc(len, GFP_KERNEL);
		if (!dst)
		if (!dst)
			return NULL;
			return NULL;
		cifs_from_ucs2(dst, (__le16 *) src, len, maxlen, codepage,
		cifs_from_utf16(dst, (__le16 *) src, len, maxlen, codepage,
			       false);
			       false);
	} else {
	} else {
		len = strnlen(src, maxlen);
		len = strnlen(src, maxlen);
@@ -264,7 +265,7 @@ cifs_strndup_from_ucs(const char *src, const int maxlen, const bool is_unicode,
 * names are little endian 16 bit Unicode on the wire
 * names are little endian 16 bit Unicode on the wire
 */
 */
int
int
cifsConvertToUCS(__le16 *target, const char *source, int srclen,
cifsConvertToUTF16(__le16 *target, const char *source, int srclen,
		 const struct nls_table *cp, int mapChars)
		 const struct nls_table *cp, int mapChars)
{
{
	int i, j, charlen;
	int i, j, charlen;
@@ -273,7 +274,7 @@ cifsConvertToUCS(__le16 *target, const char *source, int srclen,
	wchar_t tmp;
	wchar_t tmp;


	if (!mapChars)
	if (!mapChars)
		return cifs_strtoUCS(target, source, PATH_MAX, cp);
		return cifs_strtoUTF16(target, source, PATH_MAX, cp);


	for (i = 0, j = 0; i < srclen; j++) {
	for (i = 0, j = 0; i < srclen; j++) {
		src_char = source[i];
		src_char = source[i];
@@ -281,7 +282,7 @@ cifsConvertToUCS(__le16 *target, const char *source, int srclen,
		switch (src_char) {
		switch (src_char) {
		case 0:
		case 0:
			put_unaligned(0, &target[j]);
			put_unaligned(0, &target[j]);
			goto ctoUCS_out;
			goto ctoUTF16_out;
		case ':':
		case ':':
			dst_char = cpu_to_le16(UNI_COLON);
			dst_char = cpu_to_le16(UNI_COLON);
			break;
			break;
@@ -326,7 +327,7 @@ cifsConvertToUCS(__le16 *target, const char *source, int srclen,
		put_unaligned(dst_char, &target[j]);
		put_unaligned(dst_char, &target[j]);
	}
	}


ctoUCS_out:
ctoUTF16_out:
	return i;
	return i;
}
}
+10 −10
Original line number Original line Diff line number Diff line
@@ -74,15 +74,15 @@ extern const struct UniCaseRange CifsUniLowerRange[];
#endif				/* UNIUPR_NOLOWER */
#endif				/* UNIUPR_NOLOWER */


#ifdef __KERNEL__
#ifdef __KERNEL__
int cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen,
int cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen,
		    const struct nls_table *codepage, bool mapchar);
		    const struct nls_table *codepage, bool mapchar);
int cifs_ucs2_bytes(const __le16 *from, int maxbytes,
int cifs_utf16_bytes(const __le16 *from, int maxbytes,
		     const struct nls_table *codepage);
		     const struct nls_table *codepage);
int cifs_strtoUCS(__le16 *, const char *, int, const struct nls_table *);
int cifs_strtoUTF16(__le16 *, const char *, int, const struct nls_table *);
char *cifs_strndup_from_ucs(const char *src, const int maxlen,
char *cifs_strndup_from_utf16(const char *src, const int maxlen,
			      const bool is_unicode,
			      const bool is_unicode,
			      const struct nls_table *codepage);
			      const struct nls_table *codepage);
extern int cifsConvertToUCS(__le16 *target, const char *source, int maxlen,
extern int cifsConvertToUTF16(__le16 *target, const char *source, int maxlen,
			      const struct nls_table *cp, int mapChars);
			      const struct nls_table *cp, int mapChars);


#endif
#endif
+6 −6
Original line number Original line Diff line number Diff line
@@ -327,7 +327,7 @@ build_avpair_blob(struct cifs_ses *ses, const struct nls_table *nls_cp)
	attrptr->type = cpu_to_le16(NTLMSSP_AV_NB_DOMAIN_NAME);
	attrptr->type = cpu_to_le16(NTLMSSP_AV_NB_DOMAIN_NAME);
	attrptr->length = cpu_to_le16(2 * dlen);
	attrptr->length = cpu_to_le16(2 * dlen);
	blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name);
	blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name);
	cifs_strtoUCS((__le16 *)blobptr, ses->domainName, dlen, nls_cp);
	cifs_strtoUTF16((__le16 *)blobptr, ses->domainName, dlen, nls_cp);


	return 0;
	return 0;
}
}
@@ -376,7 +376,7 @@ find_domain_name(struct cifs_ses *ses, const struct nls_table *nls_cp)
					kmalloc(attrsize + 1, GFP_KERNEL);
					kmalloc(attrsize + 1, GFP_KERNEL);
				if (!ses->domainName)
				if (!ses->domainName)
						return -ENOMEM;
						return -ENOMEM;
				cifs_from_ucs2(ses->domainName,
				cifs_from_utf16(ses->domainName,
					(__le16 *)blobptr, attrsize, attrsize,
					(__le16 *)blobptr, attrsize, attrsize,
					nls_cp, false);
					nls_cp, false);
				break;
				break;
@@ -429,7 +429,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
	}
	}


	if (len) {
	if (len) {
		len = cifs_strtoUCS((__le16 *)user, ses->user_name, len, nls_cp);
		len = cifs_strtoUTF16((__le16 *)user, ses->user_name, len, nls_cp);
		UniStrupr(user);
		UniStrupr(user);
	} else {
	} else {
		memset(user, '\0', 2);
		memset(user, '\0', 2);
@@ -453,7 +453,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
			rc = -ENOMEM;
			rc = -ENOMEM;
			return rc;
			return rc;
		}
		}
		len = cifs_strtoUCS((__le16 *)domain, ses->domainName, len,
		len = cifs_strtoUTF16((__le16 *)domain, ses->domainName, len,
				      nls_cp);
				      nls_cp);
		rc =
		rc =
		crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
		crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
@@ -473,7 +473,7 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
			rc = -ENOMEM;
			rc = -ENOMEM;
			return rc;
			return rc;
		}
		}
		len = cifs_strtoUCS((__le16 *)server, ses->serverName, len,
		len = cifs_strtoUTF16((__le16 *)server, ses->serverName, len,
					nls_cp);
					nls_cp);
		rc =
		rc =
		crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
		crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
+84 −78
Original line number Original line Diff line number Diff line
@@ -821,7 +821,7 @@ PsxDelete:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
		    cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -893,7 +893,7 @@ DelFileRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->fileName, fileName,
		    cifsConvertToUTF16((__le16 *) pSMB->fileName, fileName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -938,7 +938,7 @@ RmDirRetry:
		return rc;
		return rc;


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, dirName,
		name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, dirName,
					      PATH_MAX, nls_codepage, remap);
					      PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -981,7 +981,7 @@ MkDirRetry:
		return rc;
		return rc;


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name,
		name_len = cifsConvertToUTF16((__le16 *) pSMB->DirName, name,
					      PATH_MAX, nls_codepage, remap);
					      PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -1030,7 +1030,7 @@ PsxCreat:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->FileName, name,
		    cifsConvertToUTF16((__le16 *) pSMB->FileName, name,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -1197,7 +1197,7 @@ OldOpenRetry:
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		count = 1;      /* account for one byte pad to word boundary */
		count = 1;      /* account for one byte pad to word boundary */
		name_len =
		name_len =
		   cifsConvertToUCS((__le16 *) (pSMB->fileName + 1),
		   cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1),
				      fileName, PATH_MAX, nls_codepage, remap);
				      fileName, PATH_MAX, nls_codepage, remap);
		name_len++;     /* trailing null */
		name_len++;     /* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -1304,7 +1304,7 @@ openRetry:
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		count = 1;	/* account for one byte pad to word boundary */
		count = 1;	/* account for one byte pad to word boundary */
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) (pSMB->fileName + 1),
		    cifsConvertToUTF16((__le16 *) (pSMB->fileName + 1),
				       fileName, PATH_MAX, nls_codepage, remap);
				       fileName, PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -2649,7 +2649,7 @@ renameRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName,
		    cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -2657,7 +2657,7 @@ renameRetry:
	/* protocol requires ASCII signature byte on Unicode string */
	/* protocol requires ASCII signature byte on Unicode string */
		pSMB->OldFileName[name_len + 1] = 0x00;
		pSMB->OldFileName[name_len + 1] = 0x00;
		name_len2 =
		name_len2 =
		    cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2],
		    cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2],
				       toName, PATH_MAX, nls_codepage, remap);
				       toName, PATH_MAX, nls_codepage, remap);
		name_len2 += 1 /* trailing null */  + 1 /* Signature word */ ;
		name_len2 += 1 /* trailing null */  + 1 /* Signature word */ ;
		name_len2 *= 2;	/* convert to bytes */
		name_len2 *= 2;	/* convert to bytes */
@@ -2738,10 +2738,12 @@ int CIFSSMBRenameOpenFile(const int xid, struct cifs_tcon *pTcon,
	/* unicode only call */
	/* unicode only call */
	if (target_name == NULL) {
	if (target_name == NULL) {
		sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid);
		sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid);
		len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name,
		len_of_str =
			cifsConvertToUTF16((__le16 *)rename_info->target_name,
					dummy_string, 24, nls_codepage, remap);
					dummy_string, 24, nls_codepage, remap);
	} else {
	} else {
		len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name,
		len_of_str =
			cifsConvertToUTF16((__le16 *)rename_info->target_name,
					target_name, PATH_MAX, nls_codepage,
					target_name, PATH_MAX, nls_codepage,
					remap);
					remap);
	}
	}
@@ -2795,7 +2797,7 @@ copyRetry:
	pSMB->Flags = cpu_to_le16(flags & COPY_TREE);
	pSMB->Flags = cpu_to_le16(flags & COPY_TREE);


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName,
		name_len = cifsConvertToUTF16((__le16 *) pSMB->OldFileName,
					      fromName, PATH_MAX, nls_codepage,
					      fromName, PATH_MAX, nls_codepage,
					      remap);
					      remap);
		name_len++;     /* trailing null */
		name_len++;     /* trailing null */
@@ -2804,7 +2806,7 @@ copyRetry:
		/* protocol requires ASCII signature byte on Unicode string */
		/* protocol requires ASCII signature byte on Unicode string */
		pSMB->OldFileName[name_len + 1] = 0x00;
		pSMB->OldFileName[name_len + 1] = 0x00;
		name_len2 =
		name_len2 =
		    cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2],
		    cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2],
				       toName, PATH_MAX, nls_codepage, remap);
				       toName, PATH_MAX, nls_codepage, remap);
		name_len2 += 1 /* trailing null */  + 1 /* Signature word */ ;
		name_len2 += 1 /* trailing null */  + 1 /* Signature word */ ;
		name_len2 *= 2; /* convert to bytes */
		name_len2 *= 2; /* convert to bytes */
@@ -2861,9 +2863,9 @@ createSymLinkRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifs_strtoUCS((__le16 *) pSMB->FileName, fromName, PATH_MAX
		    cifs_strtoUTF16((__le16 *) pSMB->FileName, fromName,
				    /* find define for this maxpathcomponent */
				    /* find define for this maxpathcomponent */
				  , nls_codepage);
				    PATH_MAX, nls_codepage);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;


@@ -2885,7 +2887,7 @@ createSymLinkRetry:
	data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
	data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len_target =
		name_len_target =
		    cifs_strtoUCS((__le16 *) data_offset, toName, PATH_MAX
		    cifs_strtoUTF16((__le16 *) data_offset, toName, PATH_MAX
				    /* find define for this maxpathcomponent */
				    /* find define for this maxpathcomponent */
				    , nls_codepage);
				    , nls_codepage);
		name_len_target++;	/* trailing null */
		name_len_target++;	/* trailing null */
@@ -2949,7 +2951,7 @@ createHardLinkRetry:
		return rc;
		return rc;


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len = cifsConvertToUCS((__le16 *) pSMB->FileName, toName,
		name_len = cifsConvertToUTF16((__le16 *) pSMB->FileName, toName,
					      PATH_MAX, nls_codepage, remap);
					      PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -2972,8 +2974,8 @@ createHardLinkRetry:
	data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
	data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len_target =
		name_len_target =
		    cifsConvertToUCS((__le16 *) data_offset, fromName, PATH_MAX,
		    cifsConvertToUTF16((__le16 *) data_offset, fromName,
				     nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len_target++;	/* trailing null */
		name_len_target++;	/* trailing null */
		name_len_target *= 2;
		name_len_target *= 2;
	} else {	/* BB improve the check for buffer overruns BB */
	} else {	/* BB improve the check for buffer overruns BB */
@@ -3042,7 +3044,7 @@ winCreateHardLinkRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName,
		    cifsConvertToUTF16((__le16 *) pSMB->OldFileName, fromName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -3051,7 +3053,7 @@ winCreateHardLinkRetry:
		pSMB->OldFileName[name_len] = 0x04;
		pSMB->OldFileName[name_len] = 0x04;
		pSMB->OldFileName[name_len + 1] = 0x00; /* pad */
		pSMB->OldFileName[name_len + 1] = 0x00; /* pad */
		name_len2 =
		name_len2 =
		    cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2],
		    cifsConvertToUTF16((__le16 *)&pSMB->OldFileName[name_len+2],
				       toName, PATH_MAX, nls_codepage, remap);
				       toName, PATH_MAX, nls_codepage, remap);
		name_len2 += 1 /* trailing null */  + 1 /* Signature word */ ;
		name_len2 += 1 /* trailing null */  + 1 /* Signature word */ ;
		name_len2 *= 2;	/* convert to bytes */
		name_len2 *= 2;	/* convert to bytes */
@@ -3108,7 +3110,7 @@ querySymLinkRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifs_strtoUCS((__le16 *) pSMB->FileName, searchName,
			cifs_strtoUTF16((__le16 *) pSMB->FileName, searchName,
					PATH_MAX, nls_codepage);
					PATH_MAX, nls_codepage);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -3166,8 +3168,8 @@ querySymLinkRetry:
				is_unicode = false;
				is_unicode = false;


			/* BB FIXME investigate remapping reserved chars here */
			/* BB FIXME investigate remapping reserved chars here */
			*symlinkinfo = cifs_strndup_from_ucs(data_start, count,
			*symlinkinfo = cifs_strndup_from_utf16(data_start,
						    is_unicode, nls_codepage);
					count, is_unicode, nls_codepage);
			if (!*symlinkinfo)
			if (!*symlinkinfo)
				rc = -ENOMEM;
				rc = -ENOMEM;
		}
		}
@@ -3450,8 +3452,9 @@ queryAclRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
			cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
			cifsConvertToUTF16((__le16 *) pSMB->FileName,
					 PATH_MAX, nls_codepage, remap);
					   searchName, PATH_MAX, nls_codepage,
					   remap);
		name_len++;     /* trailing null */
		name_len++;     /* trailing null */
		name_len *= 2;
		name_len *= 2;
		pSMB->FileName[name_len] = 0;
		pSMB->FileName[name_len] = 0;
@@ -3537,7 +3540,7 @@ setAclRetry:
		return rc;
		return rc;
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
			cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
			cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName,
					   PATH_MAX, nls_codepage, remap);
					   PATH_MAX, nls_codepage, remap);
		name_len++;     /* trailing null */
		name_len++;     /* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -3948,8 +3951,9 @@ QInfRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
			cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
			cifsConvertToUTF16((__le16 *) pSMB->FileName,
					PATH_MAX, nls_codepage, remap);
					   searchName, PATH_MAX, nls_codepage,
					   remap);
		name_len++;     /* trailing null */
		name_len++;     /* trailing null */
		name_len *= 2;
		name_len *= 2;
	} else {
	} else {
@@ -4086,7 +4090,7 @@ QPathInfoRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
		    cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -4255,7 +4259,7 @@ UnixQPathInfoRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
		    cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -4344,7 +4348,7 @@ findFirstRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
		    cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		/* We can not add the asterik earlier in case
		/* We can not add the asterik earlier in case
		it got remapped to 0xF03A as if it were part of the
		it got remapped to 0xF03A as if it were part of the
@@ -4656,8 +4660,9 @@ GetInodeNumberRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
			cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
			cifsConvertToUTF16((__le16 *) pSMB->FileName,
					 PATH_MAX, nls_codepage, remap);
					   searchName, PATH_MAX, nls_codepage,
					   remap);
		name_len++;     /* trailing null */
		name_len++;     /* trailing null */
		name_len *= 2;
		name_len *= 2;
	} else {	/* BB improve the check for buffer overruns BB */
	} else {	/* BB improve the check for buffer overruns BB */
@@ -4794,9 +4799,9 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
				rc = -ENOMEM;
				rc = -ENOMEM;
				goto parse_DFS_referrals_exit;
				goto parse_DFS_referrals_exit;
			}
			}
			cifsConvertToUCS((__le16 *) tmp, searchName,
			cifsConvertToUTF16((__le16 *) tmp, searchName,
					   PATH_MAX, nls_codepage, remap);
					   PATH_MAX, nls_codepage, remap);
			node->path_consumed = cifs_ucs2_bytes(tmp,
			node->path_consumed = cifs_utf16_bytes(tmp,
					le16_to_cpu(pSMBr->PathConsumed),
					le16_to_cpu(pSMBr->PathConsumed),
					nls_codepage);
					nls_codepage);
			kfree(tmp);
			kfree(tmp);
@@ -4809,7 +4814,7 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
		/* copy DfsPath */
		/* copy DfsPath */
		temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset);
		temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset);
		max_len = data_end - temp;
		max_len = data_end - temp;
		node->path_name = cifs_strndup_from_ucs(temp, max_len,
		node->path_name = cifs_strndup_from_utf16(temp, max_len,
						is_unicode, nls_codepage);
						is_unicode, nls_codepage);
		if (!node->path_name) {
		if (!node->path_name) {
			rc = -ENOMEM;
			rc = -ENOMEM;
@@ -4819,7 +4824,7 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
		/* copy link target UNC */
		/* copy link target UNC */
		temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset);
		temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset);
		max_len = data_end - temp;
		max_len = data_end - temp;
		node->node_name = cifs_strndup_from_ucs(temp, max_len,
		node->node_name = cifs_strndup_from_utf16(temp, max_len,
						is_unicode, nls_codepage);
						is_unicode, nls_codepage);
		if (!node->node_name)
		if (!node->node_name)
			rc = -ENOMEM;
			rc = -ENOMEM;
@@ -4873,8 +4878,9 @@ getDFSRetry:
	if (ses->capabilities & CAP_UNICODE) {
	if (ses->capabilities & CAP_UNICODE) {
		pSMB->hdr.Flags2 |= SMBFLG2_UNICODE;
		pSMB->hdr.Flags2 |= SMBFLG2_UNICODE;
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->RequestFileName,
		    cifsConvertToUTF16((__le16 *) pSMB->RequestFileName,
				     searchName, PATH_MAX, nls_codepage, remap);
				       searchName, PATH_MAX, nls_codepage,
				       remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
	} else {	/* BB improve the check for buffer overruns BB */
	} else {	/* BB improve the check for buffer overruns BB */
@@ -5506,7 +5512,7 @@ SetEOFRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
		    cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -5796,7 +5802,7 @@ SetTimesRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
		    cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -5877,7 +5883,7 @@ SetAttrLgcyRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
			ConvertToUCS((__le16 *) pSMB->fileName, fileName,
			ConvertToUTF16((__le16 *) pSMB->fileName, fileName,
				       PATH_MAX, nls_codepage);
				       PATH_MAX, nls_codepage);
		name_len++;     /* trailing null */
		name_len++;     /* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -6030,7 +6036,7 @@ setPermsRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
		    cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
@@ -6123,7 +6129,7 @@ QAllEAsRetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		list_len =
		list_len =
		    cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
		    cifsConvertToUTF16((__le16 *) pSMB->FileName, searchName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		list_len++;	/* trailing null */
		list_len++;	/* trailing null */
		list_len *= 2;
		list_len *= 2;
@@ -6301,7 +6307,7 @@ SetEARetry:


	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
	if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
		name_len =
		name_len =
		    cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
		    cifsConvertToUTF16((__le16 *) pSMB->FileName, fileName,
				       PATH_MAX, nls_codepage, remap);
				       PATH_MAX, nls_codepage, remap);
		name_len++;	/* trailing null */
		name_len++;	/* trailing null */
		name_len *= 2;
		name_len *= 2;
+2 −2
Original line number Original line Diff line number Diff line
@@ -3644,7 +3644,7 @@ CIFSTCon(unsigned int xid, struct cifs_ses *ses,
	if (ses->capabilities & CAP_UNICODE) {
	if (ses->capabilities & CAP_UNICODE) {
		smb_buffer->Flags2 |= SMBFLG2_UNICODE;
		smb_buffer->Flags2 |= SMBFLG2_UNICODE;
		length =
		length =
		    cifs_strtoUCS((__le16 *) bcc_ptr, tree,
		    cifs_strtoUTF16((__le16 *) bcc_ptr, tree,
			6 /* max utf8 char length in bytes */ *
			6 /* max utf8 char length in bytes */ *
			(/* server len*/ + 256 /* share len */), nls_codepage);
			(/* server len*/ + 256 /* share len */), nls_codepage);
		bcc_ptr += 2 * length;	/* convert num 16 bit words to bytes */
		bcc_ptr += 2 * length;	/* convert num 16 bit words to bytes */
@@ -3699,7 +3699,7 @@ CIFSTCon(unsigned int xid, struct cifs_ses *ses,


		/* mostly informational -- no need to fail on error here */
		/* mostly informational -- no need to fail on error here */
		kfree(tcon->nativeFileSystem);
		kfree(tcon->nativeFileSystem);
		tcon->nativeFileSystem = cifs_strndup_from_ucs(bcc_ptr,
		tcon->nativeFileSystem = cifs_strndup_from_utf16(bcc_ptr,
						      bytes_left, is_unicode,
						      bytes_left, is_unicode,
						      nls_codepage);
						      nls_codepage);


Loading