init_unistr2 length calculation

Ken Cross kcross at nssolutions.com
Wed Feb 12 18:18:00 GMT 2003


I'm not sure that 2 is a valid assumption.  We're using UTF-8 for the
Unix charset, and a multi-byte character can be as much as 6 bytes.

Ken
________________________________

Ken Cross

Network Storage Solutions
Phone 865.675.4070 ext 31
kcross at nssolutions.com 

-----Original Message-----
From: samba-technical-bounces+kcross=nssolutions.com at lists.samba.org
[mailto:samba-technical-bounces+kcross=nssolutions.com at lists.samba.org]
On Behalf Of Shirish Kalele
Sent: Wednesday, February 12, 2003 1:08 PM
To: samba-technical at samba.org
Subject: init_unistr2 length calculation


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