From owner-svn-src-stable@FreeBSD.ORG Sat Nov 23 12:17:06 2013 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 64AA3C93; Sat, 23 Nov 2013 12:17:06 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 5453B2568; Sat, 23 Nov 2013 12:17:06 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rANCH67t085741; Sat, 23 Nov 2013 12:17:06 GMT (envelope-from tijl@svn.freebsd.org) Received: (from tijl@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id rANCH6LX085740; Sat, 23 Nov 2013 12:17:06 GMT (envelope-from tijl@svn.freebsd.org) Message-Id: <201311231217.rANCH6LX085740@svn.freebsd.org> From: Tijl Coosemans Date: Sat, 23 Nov 2013 12:17:06 +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: r258496 - stable/10/lib/libiconv_modules/UTF7 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@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Nov 2013 12:17:06 -0000 Author: tijl Date: Sat Nov 23 12:17:05 2013 New Revision: 258496 URL: http://svnweb.freebsd.org/changeset/base/258496 Log: MFC r258316: Bug fixes in iconv(3) UTF-7 support. - Add ' to the list of directly encoded characters and * to the list of optionally directly encoded characters as per RFC 2152. - In _citrus_UTF7_mbtoutf16 on end of input when the next output character has only been partially decoded, save a copy of the buffer of input characters (not just its length). On the next call with more input characters this buffer is reprocessed together with the new input to form a fully decoded output character. - At the end of a base64 encoded sequence fully discard '-' (BASE64_OUT) by decrementing psenc->chlen and i. This is needed to make room in psenc->ch (input buffer) in case the next input character starts a new base64 encoded sequence. And also, if this is the end of input and no output character can be returned, this brings the encoder in the initial state as indicated by _citrus_UTF7_stdenc_get_state_desc_generic which is used by the caller to distinguish between no output and partial output. - In _citrus_UTF7_mbrtowc_priv pass the s parameter (input pointer) directly to _citrus_UTF7_mbtoutf16 instead of a copy (s0). This way s is updated correctly in case of errors. - In _citrus_UTF7_mbrtowc_priv when called with psenc->surrogate set (previous call did not have enough input), retrieve the previously decoded UTF-16 character from (psenc->cache >> psenc->bits) instead of (psenc->cache >> 2). Approved by: re (kib) Modified: stable/10/lib/libiconv_modules/UTF7/citrus_utf7.c Directory Properties: stable/10/lib/libiconv_modules/ (props changed) Modified: stable/10/lib/libiconv_modules/UTF7/citrus_utf7.c ============================================================================== --- stable/10/lib/libiconv_modules/UTF7/citrus_utf7.c Sat Nov 23 11:46:13 2013 (r258495) +++ stable/10/lib/libiconv_modules/UTF7/citrus_utf7.c Sat Nov 23 12:17:05 2013 (r258496) @@ -113,9 +113,9 @@ static const char base64[] = static const char direct[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" - "0123456789(),-./:?"; + "0123456789'(),-./:?"; -static const char option[] = "!\"#$%&';<=>@[]^_`{|}"; +static const char option[] = "!\"#$%&*;<=>@[]^_`{|}"; static const char spaces[] = " \t\r\n"; #define BASE64_BIT 6 @@ -165,6 +165,7 @@ _citrus_UTF7_mbtoutf16(_UTF7EncodingInfo *nresult = (size_t)-2; *s = s0; sv.chlen = psenc->chlen; + memcpy(sv.ch, psenc->ch, sizeof(sv.ch)); *psenc = sv; return (0); } @@ -202,6 +203,9 @@ _citrus_UTF7_mbtoutf16(_UTF7EncodingInfo goto ilseq; *u16 = (uint16_t)psenc->ch[i]; done = 1; + } else { + psenc->chlen--; + i--; } } else { psenc->cache = @@ -241,7 +245,6 @@ _citrus_UTF7_mbrtowc_priv(_UTF7EncodingI wchar_t * __restrict pwc, const char ** __restrict s, size_t n, _UTF7State * __restrict psenc, size_t * __restrict nresult) { - const char *s0; uint32_t u32; uint16_t hi, lo; size_t nr, siz; @@ -252,14 +255,13 @@ _citrus_UTF7_mbrtowc_priv(_UTF7EncodingI *nresult = (size_t)_ENCODING_IS_STATE_DEPENDENT; return (0); } - s0 = *s; if (psenc->surrogate) { - hi = (psenc->cache >> 2) & UTF16_MAX; + hi = (psenc->cache >> psenc->bits) & UTF16_MAX; if (hi < HISRG_MIN || hi > HISRG_MAX) return (EINVAL); siz = 0; } else { - err = _citrus_UTF7_mbtoutf16(ei, &hi, &s0, n, psenc, &nr); + err = _citrus_UTF7_mbtoutf16(ei, &hi, s, n, psenc, &nr); if (nr == (size_t)-1 || nr == (size_t)-2) { *nresult = nr; return (err); @@ -274,7 +276,7 @@ _citrus_UTF7_mbrtowc_priv(_UTF7EncodingI } psenc->surrogate = 1; } - err = _citrus_UTF7_mbtoutf16(ei, &lo, &s0, n, psenc, &nr); + err = _citrus_UTF7_mbtoutf16(ei, &lo, s, n, psenc, &nr); if (nr == (size_t)-1 || nr == (size_t)-2) { *nresult = nr; return (err); @@ -286,7 +288,6 @@ _citrus_UTF7_mbrtowc_priv(_UTF7EncodingI u32 = (hi << 10 | lo) + SRG_BASE; siz += nr; done: - *s = s0; if (pwc != NULL) *pwc = (wchar_t)u32; if (u32 == (uint32_t)0) {