From owner-svn-src-stable-10@freebsd.org Wed Sep 2 05:55:58 2015 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A2EB59C7289; Wed, 2 Sep 2015 05:55:58 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7977A96; Wed, 2 Sep 2015 05:55:58 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t825twBw027172; Wed, 2 Sep 2015 05:55:58 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t825twGv027171; Wed, 2 Sep 2015 05:55:58 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201509020555.t825twGv027171@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Wed, 2 Sep 2015 05:55:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287393 - stable/10/lib/libc/locale X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Sep 2015 05:55:58 -0000 Author: bapt Date: Wed Sep 2 05:55:57 2015 New Revision: 287393 URL: https://svnweb.freebsd.org/changeset/base/287393 Log: MFC: r286490,r286491,r287125 Per rfc3629 value greater than 0x10ffff should be rejected (r286490,r286491) Make UTF-8 parsing and generation more strict. (r287125 by ed) - in mbrtowc() we need to disallow codepoints above 0x10ffff. - In wcrtomb() we need to disallow codepoints between 0xd800 and 0xdfff. Modified: stable/10/lib/libc/locale/utf8.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/locale/utf8.c ============================================================================== --- stable/10/lib/libc/locale/utf8.c Wed Sep 2 05:45:47 2015 (r287392) +++ stable/10/lib/libc/locale/utf8.c Wed Sep 2 05:55:57 2015 (r287393) @@ -145,14 +145,6 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc, mask = 0x07; want = 4; lbound = 0x10000; - } else if ((ch & 0xfc) == 0xf8) { - mask = 0x03; - want = 5; - lbound = 0x200000; - } else if ((ch & 0xfe) == 0xfc) { - mask = 0x01; - want = 6; - lbound = 0x4000000; } else { /* * Malformed input; input is not UTF-8. @@ -199,7 +191,7 @@ _UTF8_mbrtowc(wchar_t * __restrict pwc, errno = EILSEQ; return ((size_t)-1); } - if (wch >= 0xd800 && wch <= 0xdfff) { + if ((wch >= 0xd800 && wch <= 0xdfff) || wch > 0x10ffff) { /* * Malformed input; invalid code points. */ @@ -326,17 +318,15 @@ _UTF8_wcrtomb(char * __restrict s, wchar lead = 0xc0; len = 2; } else if ((wc & ~0xffff) == 0) { + if (wc >= 0xd800 && wc <= 0xdfff) { + errno = EILSEQ; + return ((size_t)-1); + } lead = 0xe0; len = 3; - } else if ((wc & ~0x1fffff) == 0) { + } else if (wc >= 0 && wc <= 0x10ffff) { lead = 0xf0; len = 4; - } else if ((wc & ~0x3ffffff) == 0) { - lead = 0xf8; - len = 5; - } else if ((wc & ~0x7fffffff) == 0) { - lead = 0xfc; - len = 6; } else { errno = EILSEQ; return ((size_t)-1);