[PATCH] newlib: getlocalename_l: Avoid strcpy onto const area on "C" locale
Jeff Johnston
jjohnstn@redhat.com
Tue Aug 25 00:14:11 GMT 2026
Patch applied. Thanks.
-- Jeff J.
On Mon, Aug 24, 2026 at 4:03 AM Takashi Yano <takashi.yano@nifty.ne.jp>
wrote:
> With the commit a0fe984953dd ("getlocalename_l: allow LC_ALL category"),
> the code attempts to copy locale string to `locobj->locale_string`,
> in __currentlocale() in _getlocalename_l_r(). However, if `locobj` is
> the "C" locale, it points to the const area. This results in a crash.
>
> This patch simply returns "C" when the `locobj` represents the C
> locale, instead of cunstructing LC_ALL string from `categories[]`
> because all the `categories[]` are always "C" for the C locale.
>
> Fixes: a0fe984953dd ("getlocalename_l: allow LC_ALL category")
> Addresses: https://cygwin.com/pipermail/cygwin/2026-August/259965.html
> Reported-by: Tony Cook <tony@develop-help.com>
> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
> ---
> newlib/libc/locale/getlocalename_l.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/newlib/libc/locale/getlocalename_l.c
> b/newlib/libc/locale/getlocalename_l.c
> index 1f18f828a..7ad4331b4 100644
> --- a/newlib/libc/locale/getlocalename_l.c
> +++ b/newlib/libc/locale/getlocalename_l.c
> @@ -63,6 +63,8 @@ _getlocalename_l_r (struct _reent *ptr, int category,
> struct __locale_t *locobj)
> if (locobj == LC_GLOBAL_LOCALE)
> return __currentlocale (__get_global_locale (),
> _REENT_GETLOCALENAME_L_BUF (ptr));
> + else if (locobj == __get_C_locale ())
> + return "C";
> return __currentlocale (locobj, locobj->locale_string);
> }
> if (locobj == LC_GLOBAL_LOCALE)
> --
> 2.51.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/newlib/attachments/20260824/9f82f7f3/attachment.htm>
More information about the Newlib
mailing list