From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17318 invoked from network); 8 Dec 2023 10:46:40 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 8 Dec 2023 10:46:40 -0000 Received: (qmail 2031 invoked by uid 550); 8 Dec 2023 10:46:29 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 1996 invoked from network); 8 Dec 2023 10:46:29 -0000 X-Proofpoint-ORIG-GUID: 34XyKjgysLmm5TEnNZ7dTtoCbbaHSUsF X-Proofpoint-GUID: 34XyKjgysLmm5TEnNZ7dTtoCbbaHSUsF X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.619,18.0.997 definitions=2023-12-08_06:2023-12-07,2023-12-08 signatures=0 X-Proofpoint-Spam-Details: rule=interactive_user_notspam policy=interactive_user score=0 adultscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312080089 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=content-type : mime-version : subject : from : in-reply-to : date : cc : content-transfer-encoding : message-id : references : to; s=20180706; bh=1/yqw8Wzm6vhEtUNCv5+nuv4LZQkZEN1ror8qDOzBl4=; b=YsTJBOIfbfK4s+nYw5a0yxgpU3fzMTCE8pdez2mO51oGIGOTfq8lpXl7Tv2YpAB/e+0G GbQlvxND8Mvt/6+C6jJ46i+8uwFBpfKceb+BuksPJMhZz1l/FW6HqucNewJmf+xZ8Cl2 M4ZWMhtUY50ulQNUh+5CG4t32GN22s567aeLja4/pPYp8cIWUFIEsSaAMCZ7Fs8TK7rP rtBDuZIBs5rKUdWb9dt6Bu0BoI7D9C32eUZZUR8lXlFs0FzkqMUuOXmbjQ1zKie2U62l 1py0DwxNQLcEu8beYqh2W5I0VxuDYQQORm20SoqrDxC88aQZonCT2sSA0bK2yKih4eoz zg== X-Va-A: X-Va-T-CD: 14dc138f66d48087821ca031f1b11e6a X-Va-E-CD: 938c8e4fd76e3e013edeb3d41379f883 X-Va-R-CD: 8a2faf3de2027b4a0bc7941d26d4bbde X-Va-ID: ab1dff5f-f3f4-47d8-95b5-e3abee067b45 X-Va-CD: 0 X-V-A: X-V-T-CD: 14dc138f66d48087821ca031f1b11e6a X-V-E-CD: 938c8e4fd76e3e013edeb3d41379f883 X-V-R-CD: 8a2faf3de2027b4a0bc7941d26d4bbde X-V-ID: e79de99d-e91b-41e8-a59c-77afda489be8 X-V-CD: 0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.619,18.0.997 definitions=2023-12-08_06:2023-12-07,2023-12-08 signatures=0 Content-type: text/plain; charset=utf-8 MIME-version: 1.0 (Mac OS X Mail 16.0 \(3774.300.61.1.2\)) From: Alastair Houghton In-reply-to: Date: Fri, 08 Dec 2023 10:46:15 +0000 Cc: Rich Felker Content-transfer-encoding: quoted-printable Message-id: <9AF32F3B-1889-4799-9379-EF860BE3E85F@apple.com> References: <1390B046-C845-406F-8AED-620F2DD16BC0@apple.com> <20230810155115.GT4163@brightrain.aerifal.cx> <267261EB-1DFA-4072-89F0-B62F5DDE5F09@apple.com> <3DD8D02A-0802-494E-B9E8-F00B457B86F6@apple.com> <25283A51-7FB1-4CB1-9C26-DF06F69922BC@apple.com> To: musl@lists.openwall.com X-Mailer: Apple Mail (2.3774.300.61.1.2) Subject: Re: [musl] setlocale() again On 5 Dec 2023, at 15:19, Alastair Houghton wrote: >=20 >> Maybe I=E2=80=99ve missed a reply somewhere along the lines; here=E2=80= =99s a tentative patch that just does the simple thing of making = setlocale(LC_ALL, "") pick the C.UTF-8 locale if it=E2=80=99s unable to = find the locale specified in the environment. >=20 > [snip] >=20 > Hah. So, testing that patch, having removed my hacks to avoid using = Musl=E2=80=99s locale support, I find it doesn=E2=80=99t actually work = (for two reasons; one, NULL doesn=E2=80=99t mean not found, it means = =E2=80=9Cuse =E2=80=98C=E2=80=99=E2=80=9D; and two, there is some very = odd code in setlocale.c that causes things to go wrong if the specified = name is longer than LOCALE_NAME_MAX). >=20 > I=E2=80=99ll come back with an updated patch in a bit. Updated patch: =3D=3D=3D=3D Cut here =3D=3D=3D=3D diff --git a/src/locale/locale_map.c b/src/locale/locale_map.c index da61f7fc..097da1ad 100644 --- a/src/locale/locale_map.c +++ b/src/locale/locale_map.c @@ -31,7 +31,7 @@ static const char envvars[][12] =3D { volatile int __locale_lock[1]; volatile int *const __locale_lockptr =3D __locale_lock; =20 -const struct __locale_map *__get_locale(int cat, const char *val) +const struct __locale_map *__get_locale(int cat, const char *locale) { static void *volatile loc_head; const struct __locale_map *p; @@ -39,6 +39,7 @@ const struct __locale_map *__get_locale(int cat, const = char *val) const char *path =3D 0, *z; char buf[256]; size_t l, n; + const char *val =3D locale; =20 if (!*val) { (val =3D getenv("LC_ALL")) && *val || @@ -92,22 +93,18 @@ const struct __locale_map *__get_locale(int cat, = const char *val) } } =20 - /* If no locale definition was found, make a locale map - * object anyway to store the name, which is kept for the - * sake of being able to do message translations at the - * application level. */ - if (!new && (new =3D malloc(sizeof *new))) { - new->map =3D __c_dot_utf8.map; - new->map_size =3D __c_dot_utf8.map_size; - memcpy(new->name, val, n); - new->name[n] =3D 0; - new->next =3D loc_head; - loc_head =3D new; - } + /* If no locale definition was found, and we specified a + * locale name of "", return the C.UTF-8 locale. */ + if (!new && !*locale) new =3D (void *)&__c_dot_utf8; =20 /* For LC_CTYPE, never return a null pointer unless the * requested name was "C" or "POSIX". */ if (!new && cat =3D=3D LC_CTYPE) new =3D (void *)&__c_dot_utf8; =20 + /* Returning NULL means "C locale"; if we get here and + * there's no locale, return failure instead. */ + if (!new) + return LOC_MAP_FAILED; + return new; } diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c index 360c4437..9842d95d 100644 --- a/src/locale/setlocale.c +++ b/src/locale/setlocale.c @@ -28,12 +28,14 @@ char *setlocale(int cat, const char *name) const char *p =3D name; for (i=3D0; i LOCALE_NAME_MAX) + lm =3D LOC_MAP_FAILED; + else { memcpy(part, p, z-p); part[z-p] =3D 0; if (*z) p =3D z+1; + lm =3D __get_locale(i, part); } - lm =3D __get_locale(i, part); if (lm =3D=3D LOC_MAP_FAILED) { UNLOCK(__locale_lock); return 0; =3D=3D=3D=3D Cut here =3D=3D=3D=3D