init_unistr2 length calculation

Shirish Kalele kalele at veritas.com
Wed Feb 12 18:08:24 GMT 2003


Hi,

In init_unistr2, the string length for the UNISTR2 structure seems to be set
equal to the number of bytes occupied by the string when encoded in the Unix
charset (i.e. the value returned by strlen()). This is not necessarily the
number of characters in the string (given UTF-8 and other variable-byte
charsets).

Shouldn't this actually be set to half the number of bytes occupied by the
string after encoding it in UCS2? Here's a patch that does this.

Thanks,
Shirish

Index: rpc_parse/parse_misc.c
===================================================================
RCS file: /cvsroot/samba/source/rpc_parse/parse_misc.c,v
retrieving revision 1.94.2.8
diff -u -r1.94.2.8 parse_misc.c
--- rpc_parse/parse_misc.c 28 Jan 2003 21:09:56 -0000 1.94.2.8
+++ rpc_parse/parse_misc.c 11 Feb 2003 19:52:32 -0000
@@ -889,10 +889,6 @@
 {
  ZERO_STRUCTP(str);

- /* set up string lengths. */
- str->uni_max_len = (uint32)len;
- str->undoc       = 0;
- str->uni_str_len = (uint32)len;

  if (len < MAX_UNISTRLEN)
   len = MAX_UNISTRLEN;
@@ -912,7 +908,13 @@
  if (buf==NULL)
   return;

- rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
+ len = rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
+ len /= 2;
+ /* set up string lengths. */
+ str->uni_max_len = (uint32)len;
+ str->undoc       = 0;
+ str->uni_str_len = (uint32)len;
+
 }

 /**



More information about the samba-technical mailing list