Subject: Re: lib/36938: mbtowc misbehaving after invalid char sequence
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Takehiko NOZAKI <th-nozaki@netwrk.co.jp>
List: netbsd-bugs
Date: 11/26/2007 15:35:02
The following reply was made to PR lib/36938; it has been noted by GNATS.

From: Takehiko NOZAKI <th-nozaki@netwrk.co.jp>
To: gnats-bugs@NetBSD.org
Cc: neil@daikokuya.co.uk
Subject: Re: lib/36938: mbtowc misbehaving after invalid char sequence
Date: Tue, 27 Nov 2007 00:28:49 +0900

 hi, all.
 
 i confirm that Neil's testcase works well on Solaris,
 so i decided my mind that this is Citrus's defect.
 
 and few days ago, Shiozaki-san(Citrus lead) suggests me following patch:
 
 Index: citrus_ctype_template.h
 ===================================================================
 RCS file: /cvsroot/src/lib/libc/citrus/citrus_ctype_template.h,v
 retrieving revision 1.33
 diff -u -r1.33 citrus_ctype_template.h
 --- citrus_ctype_template.h	18 Sep 2007 15:12:07 -0000	1.33
 +++ citrus_ctype_template.h	26 Nov 2007 15:13:21 -0000
 @@ -209,14 +209,13 @@
  
  	state = *psenc;
  	err = _FUNCNAME(mbrtowc_priv)(ei, pwc, (const char **)&s, n, psenc, &nr);
 +	if (nr == (size_t)-2)
 +		err = EILSEQ;
  	if (err) {
 -		*nresult = -1;
 -		return (err);
 -	}
 -	if (nr == (size_t)-2) {
 +		/* In error case, we should restore the state. */
  		*psenc = state;
  		*nresult = -1;
 -		return (EILSEQ);
 +		return (err);
  	}
  
  	*nresult = (int)nr;
 
 
 applied this patch, if error -- byte sequeces is:
   1) illegal byte sequence
   2) too short to convert
 -- has been occured, restore internal-state
 as it was before mbtowc(3) called(assumes as initial state).
 
 i've commited this patch now.
 please recompile and install lib${ENCODING}.so by following instruction:
 
 # cd src/lib/i18n_modules
 # make depend all install
 
 it will fix the problem, sorry for long inconvenience.
 
 adding some comments is TBD.
 i shall write it in engrish, not english ;-<
 
 very truly yours.
 --
 Takehiko NOZAKI <tnozaki@NetBSD.org>