From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 5BEF13858D28; Fri, 12 Aug 2022 10:29:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BEF13858D28 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org, newlib-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_3-branch] newlocale: fix crash when trying to write to __C_locale X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: 55eb8b193f9f6e7b8733bf83c9f7f9d2818c67d3 X-Git-Newrev: b612db5b14728214ca09355af5d1490df2fa1c2f Message-Id: <20220812102957.5BEF13858D28@sourceware.org> Date: Fri, 12 Aug 2022 10:29:57 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Aug 2022 10:29:57 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Db612db5b147= 28214ca09355af5d1490df2fa1c2f commit b612db5b14728214ca09355af5d1490df2fa1c2f Author: Corinna Vinschen Date: Thu Aug 11 19:27:48 2022 +0200 newlocale: fix crash when trying to write to __C_locale =20 This simple testcase: =20 locale_t st =3D newlocale(LC_ALL_MASK, "C", (locale_t)0); locale_t st2 =3D newlocale(LC_CTYPE_MASK, "en_US.UTF-8", st); =20 is sufficient to reproduce a crash in _newlocale_r. After the first ca= ll to newlocale, `st' points to __C_locale, which is const. When using `s= t' as locale base in the second call, _newlocale_r tries to set pointers inside base to NULL. This is bad if base is __C_locale, obviously. =20 Add a test to avoid trying to overwrite pointer values inside base if base is __C_locale. =20 Signed-off-by: Corinna Vinschen Diff: --- newlib/libc/locale/newlocale.c | 3 ++- winsup/cygwin/release/3.3.6 | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/newlib/libc/locale/newlocale.c b/newlib/libc/locale/newlocale.c index 0789d5fd9..08f29dbcc 100644 --- a/newlib/libc/locale/newlocale.c +++ b/newlib/libc/locale/newlocale.c @@ -188,7 +188,8 @@ _newlocale_r (struct _reent *p, int category_mask, cons= t char *locale, if (tmp_locale.lc_cat[i].buf =3D=3D (const void *) -1) { tmp_locale.lc_cat[i].buf =3D base->lc_cat[i].buf; - base->lc_cat[i].ptr =3D base->lc_cat[i].buf =3D NULL; + if (base !=3D __get_C_locale ()) + base->lc_cat[i].ptr =3D base->lc_cat[i].buf =3D NULL; } #endif /* __HAVE_LOCALE_INFO__ */ _freelocale_r (p, base); diff --git a/winsup/cygwin/release/3.3.6 b/winsup/cygwin/release/3.3.6 index 364e0cb0d..1da4fa26c 100644 --- a/winsup/cygwin/release/3.3.6 +++ b/winsup/cygwin/release/3.3.6 @@ -39,3 +39,6 @@ Bug Fixes - Fix a path handling bug that could cause a non-existing file to be treated as the current directory. Addresses: https://cygwin.com/pipermail/cygwin/2022-August/252030.html + +- Fix a crash in newlocale. + Addresses: https://cygwin.com/pipermail/cygwin/2022-August/252043.html