[PATCH] newlib: getlocalename_l: Avoid strcpy onto const area on "C" locale
Takashi Yano <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]>
Signed-off-by: Takashi Yano <[email protected]>
---
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