From owner-freebsd-hackers Thu Jul 25 04:20:29 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id EAA14697 for hackers-outgoing; Thu, 25 Jul 1996 04:20:29 -0700 (PDT) Received: from yokogawa.co.jp (yhqfm.yokogawa.co.jp [202.33.29.34]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id EAA14665 for ; Thu, 25 Jul 1996 04:20:25 -0700 (PDT) Received: from sjc.yokogawa.co.jp.yokogawa.co.jp ([133.140.4.100]) by yokogawa.co.jp (8.6.9+2.4Wb3/3.3Wb4-firewall:08/09/94) with ESMTP id UAA14240 for ; Thu, 25 Jul 1996 20:20:21 +0900 Received: from leia.pa.yokogawa.co.jp by sjc.yokogawa.co.jp.yokogawa.co.jp (8.7.1+2.6Wbeta4/6.4J.6-YOKOGAWA-R/GW) id UAA12209; Thu, 25 Jul 1996 20:20:19 +0900 (JST) Received: from sapphire by leia.pa.yokogawa.co.jp (1.38.193.4/6.4J.6-YOKOGAWA/pa) id AA13554; Thu, 25 Jul 1996 20:20:19 +0900 Received: from localhost by sapphire.pa.yokogawa.co.jp (8.6.12/3.3Wb) id UAA00307; Thu, 25 Jul 1996 20:20:17 +0900 Message-Id: <199607251120.UAA00307@sapphire.pa.yokogawa.co.jp> To: freebsd-hackers@freebsd.org Subject: patch for the 'sgetrune' of EUC encoding From: =?ISO-2022-JP?B?GyRCRURDZkh+SmY7UhsoQg==?= X-Mailer: Mew version 1.06 on Emacs 19.28.2, Mule 2.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Date: Thu, 25 Jul 1996 20:20:17 +0900 Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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