[Samba] Conversion error: Illegal multibyte sequence

Jeremy Allison jra at samba.org
Mon Sep 9 16:40:06 MDT 2013


On Fri, Sep 06, 2013 at 05:04:53PM -0700, Jeremy Allison wrote:
> On Sat, Sep 07, 2013 at 02:02:26AM +0200, Laurent Blume wrote:
> > On 2013-09-06 10:54 PM, Jeremy Allison wrote:
> > 
> > > Either that or add another debug inside
> > > convert_string_internal() to print out
> > > the values of srclen and i_len at various
> > > points and try and determine why it's off
> > > by one.
> > 
> > Well, it was /quite/ further than that.
> > 
> > I think I got it this time, in sources3/smbd/mangle_hash2.c:
> > 
> >                        /*
> >                          * Note that if CH_UNIX is utf8 a string may be 3
> >                          * bytes, but this is ok as mb utf8 characters don't
> >                          * contain embedded ascii bytes. We are really
> > checking
> >                          * for mb UNIX asian characters like Japanese
> > (SJIS) here.
> >                          * JRA.
> >                          */
> >                         DEBUG(3, ("DEBUG ++ name, %s\n", name));
> > >>>>                        if (convert_string(CH_UNIX, CH_UTF16LE,
> > name, 2, mbc, 2, False) == 2) {
> >                                 /* Was a good mb string. */
> >                                 name += 2;
> >                                 continue;
> >                         }
> >                         DEBUG(3, ("DEBUG -- name, %s\n", name));
> > 
> > 
> > Why is the length here hardcoded to 2?
> > 
> > It's past 2am around here, so I could be missing something, time for bed.
> 
> Woo hoo ! I think you've found an oooooold old bug :-).
> 
> I'll take a look at that asap.

Ok, here is a fix for 3.6.x. Can you test this and see
if it fixes the problem ? If so, I'll get this fixed
in master and back-ported to all releases.

Thanks !

Jeremy.
-------------- next part --------------
diff --git a/source3/smbd/mangle_hash2.c b/source3/smbd/mangle_hash2.c
index 5aafe2f..e1aedf1 100644
--- a/source3/smbd/mangle_hash2.c
+++ b/source3/smbd/mangle_hash2.c
@@ -626,7 +626,8 @@ static bool is_legal_name(const char *name)
 	while (*name) {
 		if (((unsigned int)name[0]) > 128 && (name[1] != 0)) {
 			/* Possible start of mb character. */
-			char mbc[2];
+			size_t size = 0;
+			(void)next_codepoint(name, &size);
 			/*
 			 * Note that if CH_UNIX is utf8 a string may be 3
 			 * bytes, but this is ok as mb utf8 characters don't
@@ -634,7 +635,7 @@ static bool is_legal_name(const char *name)
 			 * for mb UNIX asian characters like Japanese (SJIS) here.
 			 * JRA.
 			 */
-			if (convert_string(CH_UNIX, CH_UTF16LE, name, 2, mbc, 2, False) == 2) {
+			if (size == 2) {
 				/* Was a good mb string. */
 				name += 2;
 				continue;


More information about the samba mailing list