[newlib-cygwin/cygwin-3_6-branch] newlib: getlocalename_l: Avoid strcpy onto const area on "C" locale

Takashi Yano tyan0@sourceware.org
Wed Aug 26 10:47:37 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=64a1ec49c5ea4d5ad9813fa7fd5ad0e49531b47a

commit 64a1ec49c5ea4d5ad9813fa7fd5ad0e49531b47a
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Mon Aug 24 17:02:28 2026 +0900

    newlib: getlocalename_l: Avoid strcpy onto const area on "C" locale
    
    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 constructing 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>
    (cherry picked from commit 51532d272764a0e0ba2c4dba9867a67fe1f9e83d)

Diff:
---
 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)


More information about the Newlib-cvs mailing list