standards/188036: mblen(3) in EUC locales causes crash and segmentation fault.
David Chisnall
theraven at FreeBSD.org
Mon Mar 31 09:10:01 UTC 2014
The following reply was made to PR standards/188036; it has been noted by GNATS.
From: David Chisnall <theraven at FreeBSD.org>
To: Tomohisa Tanaka <tomohisa.tanaka at gmail.com>
Cc: freebsd-gnats-submit at FreeBSD.org
Subject: Re: standards/188036: mblen(3) in EUC locales causes crash and segmentation fault.
Date: Mon, 31 Mar 2014 10:03:57 +0100
On 28 Mar 2014, at 22:21, Tomohisa Tanaka <tomohisa.tanaka at gmail.com> =
wrote:
>=20
>> Number: 188036
>> Category: standards
>> Synopsis: mblen(3) in EUC locales causes crash and segmentation =
fault.
>> Confidential: no
>> Severity: non-critical
>> Priority: low
>> Responsible: freebsd-standards
>> State: open
>> Quarter: =20
>> Keywords: =20
>> Date-Required:
>> Class: sw-bug
>> Submitter-Id: current-users
>> Arrival-Date: Fri Mar 28 22:30:00 UTC 2014
>> Closed-Date:
>> Last-Modified:
>> Originator: Tomohisa Tanaka
>> Release: FreeBSD 9.2-RELEASE-p3
>> Organization:
>> Environment:
> FreeBSD freebsd9 9.2-RELEASE-p3 FreeBSD 9.2-RELEASE-p3 #0: Sat Jan 11 =
03:25:02 UTC 2014 =
root at amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64
>> Description:
> Calling function mblen(3) in EUC locales results in crash and
> segmentation fault. To repeat the problem, both setlocale(3) and
> uselocale(3) must be called before calling mblen(3).
>=20
> I think it is because the value of _CurrentRuneLocale->__variable in
> /usr/src/lib/libc/locale/euc.c is always NULL after calling both
> setlocale(3) and uselocale(3).
>=20
>> How-To-Repeat:
> % cat main.c
> #include <stdio.h>
> #include <stdlib.h>
> #include <locale.h>
> #include <xlocale.h>
>=20
> int
> main(void)
> {
> printf("setlocale: %s\n", setlocale(LC_ALL, ""));
>=20
> locale_t newLocale =3D newlocale(LC_ALL_MASK, "C", NULL);
> locale_t oldLocale =3D uselocale(newLocale);
> /* ... */
> uselocale(oldLocale);
>=20
> printf("%d\n", mblen("a", 1));
> return 0;
> }
> % gcc -g3 -std=3Dc99 main.c
> % setenv LC_MESSAGES C
> % env LANG=3Dzh_CN.eucCN ./a.out
> setlocale: =
zh_CN.eucCN/zh_CN.eucCN/zh_CN.eucCN/zh_CN.eucCN/zh_CN.eucCN/C
> Segmentation fault (core dumped)
> % env LANG=3Dko_KR.eucKR ./a.out
> setlocale: =
ko_KR.eucKR/ko_KR.eucKR/ko_KR.eucKR/ko_KR.eucKR/ko_KR.eucKR/C
> Segmentation fault (core dumped)
> % env LANG=3Dja_JP.eucJP ./a.out
> setlocale: =
ja_JP.eucJP/ja_JP.eucJP/ja_JP.eucJP/ja_JP.eucJP/ja_JP.eucJP/C
> Segmentation fault (core dumped)
> % env LANG=3Dja_JP.UTF-8 ./a.out
> setlocale: =
ja_JP.UTF-8/ja_JP.UTF-8/ja_JP.UTF-8/ja_JP.UTF-8/ja_JP.UTF-8/C
> 1
>=20
>> Fix:
> diff -ur /usr/src/lib/libc/locale/euc.c locale/euc.c
> --- /usr/src/lib/libc/locale/euc.c 2013-09-27 10:07:50.000000000 =
+0900
> +++ locale/euc.c 2014-03-29 06:16:10.000000000 +0900
> @@ -134,7 +134,8 @@
> return (ps =3D=3D NULL || ((const _EucState *)ps)->want =3D=3D =
0);
> }
>=20
> -#define CEI ((_EucInfo *)(_CurrentRuneLocale->__variable))
> +#define CEI \
> + ((_EucInfo *)(XLOCALE_CTYPE(__get_locale())->runes->__variable))
>=20
> #define _SS2 0x008e
> #define _SS3 0x008f
>=20
>=20
>=20
> Patch attached with submission follows:
>=20
> diff -ur /usr/src/lib/libc/locale/euc.c locale/euc.c
> --- /usr/src/lib/libc/locale/euc.c 2013-09-27 10:07:50.000000000 =
+0900
> +++ locale/euc.c 2014-03-29 06:16:10.000000000 +0900
> @@ -134,7 +134,8 @@
> return (ps =3D=3D NULL || ((const _EucState *)ps)->want =3D=3D =
0);
> }
>=20
> -#define CEI ((_EucInfo *)(_CurrentRuneLocale->__variable))
> +#define CEI \
> + ((_EucInfo *)(XLOCALE_CTYPE(__get_locale())->runes->__variable))
>=20
> #define _SS2 0x008e
> #define _SS3 0x008f
I think the fix should actually be:
Index: locale/euc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- locale/euc.c (revision 263226)
+++ locale/euc.c (working copy)
@@ -134,7 +134,7 @@
return (ps =3D=3D NULL || ((const _EucState *)ps)->want =3D=3D =
0);
}
=20
-#define CEI ((_EucInfo *)(_CurrentRuneLocale->__variable))
+#define CEI ((_EucInfo =
*)(__getCurrentRuneLocale()->__variable))
=20
#define _SS2 0x008e
#define _SS3 0x008f
Please can you test this and let me know if it fixes it for you?
David=
More information about the freebsd-standards
mailing list