Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Jul 1996 20:20:17 +0900
From:      =?ISO-2022-JP?B?GyRCRURDZkh+SmY7UhsoQg==?= <mihoko@pa.yokogawa.co.jp>
To:        freebsd-hackers@freebsd.org
Subject:   patch for the 'sgetrune' of EUC encoding
Message-ID:  <199607251120.UAA00307@sapphire.pa.yokogawa.co.jp>

next in thread | raw e-mail | index | archive | help

Hello all,

I found a problem in sgetrune of EUC encoding.

That is, The library function 'mblen(3)' doesn't return the error
when the second byte is not set MSB.
I make the following patch for this problem.
It is available for 2.1.0R, 2.1.5R, and -current.

How about it ?

--------< patch for /usr/src/lib/libc/locale/euc.c >------------------------
--- euc.c	Thu May 26 22:56:45 1994
+++ euc.c.new	Thu Jul 25 19:12:36 1996
@@ -136,6 +136,7 @@
 {
 	rune_t rune = 0;
 	int len, set;
+	unsigned char c;
 
 	if (n < 1 || (len = CEI->count[set = _euc_set(*string)]) > n) {
 		if (result)
@@ -147,11 +148,20 @@
 	case 2:
 		--len;
 		++string;
-		/* FALLTHROUGH */
 	case 1:
+		while (len-- > 0) {
+			/* '0x80-0x9f' are control codes */
+			if ((c = (unsigned char)*string++) < 0xa0) {
+				if (result)
+					*result = string;
+				return (_INVALID_RUNE);
+			};
+			rune = (rune << 8) | ((u_int)(c) & 0xff);
+		}
+		break;
+		/* FALLTHROUGH */
 	case 0:
-		while (len-- > 0)
-			rune = (rune << 8) | ((u_int)(*string++) & 0xff);
+		rune = (u_int)(*string++) & 0xff;
 		break;
 	}
 	if (result)

------------------- cut cut cut -------------------------------

--
Mihoko Tanaka
<mihoko@pa.yokogawa.co.jp>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607251120.UAA00307>