[linux-cifs-client] patch for properly converting Japanese et al to utf8

David Wuertele dave-gnus at bfnet.com
Wed Sep 29 21:20:34 GMT 2004


This patch works for me.  Please give it a review.

The problem was that file.c calls cifs_strfromUCS_le() and
cifs_strtoUCS_wrapped() with the same input and output strings.  This
results in an in-place copy, which breaks when the character pointer
doesn't advance the same amount for the source and the target
(i.e. Japanese utf-8 vs utf-16).

I wrapped the functions and used a temporary buffer to ensure that the
target and destination are different buffers.  The only issue I can
imagine is if the length can be over MAX_PATHCONF, or if the length of
the input string is less than MAX_PATHCONF.  I didn't check these
cases.

--- cifs/cifs_unicode.c~	2004-07-13 15:25:04.000000000 -0700
+++ cifs/cifs_unicode.c	2004-09-29 14:11:51.000000000 -0700
@@ -34,6 +34,16 @@
 cifs_strfromUCS_le(char *to, const wchar_t * from,	/* LITTLE ENDIAN */
 		   int len, const struct nls_table *codepage)
 {
+  char tmpbuf[MAX_PATHCONF];
+  int retlen = cifs_strfromUCS_le_wrapped(tmpbuf, from, len, codepage);
+  memcpy (to, tmpbuf, retlen);
+  return retlen;
+}
+
+int
+cifs_strfromUCS_le_wrapped(char *to, const wchar_t * from,	/* LITTLE ENDIAN */
+		   int len, const struct nls_table *codepage)
+{
 	int i;
 	int outlen = 0;
 
@@ -63,6 +73,16 @@
 cifs_strtoUCS(wchar_t * to, const char *from, int len,
 	      const struct nls_table *codepage)
 {
+  wchar_t tmpbuf[MAX_PATHCONF];
+  int retlen = cifs_strtoUCS_wrapped(tmpbuf, from, len, codepage);
+  memcpy (to, tmpbuf, retlen * 2);
+  return retlen;
+}
+
+int
+cifs_strtoUCS_wrapped(wchar_t * to, const char *from, int len,
+		      const struct nls_table *codepage)
+{
 	int charlen;
 	int i;
 



More information about the linux-cifs-client mailing list