diff options
| author | Corinna Vinschen <corinna@vinschen.de> | 2026-04-24 12:46:08 +0200 |
|---|---|---|
| committer | Corinna Vinschen <corinna@vinschen.de> | 2026-04-24 12:46:08 +0200 |
| commit | 4ba7eff4d15af0f749d1913703a25c045d40fa90 (patch) | |
| tree | 2b20f73c98c719f63a2379c291569a00667302a6 | |
| parent | 8f1d2b499bc9e8007321090c1859e55c7ce7d417 (diff) | |
| download | newlib-main.tar.gz newlib-main.tar.bz2 newlib-main.zip | |
jp2uc/up2jc: avoid crash due to invalid pointerHEADgithub/mastergithub/mainmastermain
Commit 4356ccd02c9c ("towupper/towlower: handle Turkic language special
casing") changed the locale pointer in calls to towctrans_l from a NULL
pointer to LC_GLOBAL_LOCALE, which is defined as -1.
Unfortunately jp2uc_l/up2jc_l just expect a NULL or non-NULL pointer,
so LC_GLOBAL_LOCALE as input is derefenced later on and the call crashes.
To fix this problem, handle LC_GLOBAL_LOCALE just as if a NULL pointer
has been passed to the function. Keep the NULL pointer handling intact
for backward compatibility.
Fixes: 4356ccd02c9c ("towupper/towlower: handle Turkic language special casing")
Reported-by: Christophe Lyon <christophe.lyon.oss@gmail.com>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
| -rw-r--r-- | newlib/libc/ctype/jp2uc.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/newlib/libc/ctype/jp2uc.c b/newlib/libc/ctype/jp2uc.c index 5e30f09be..a32561eb7 100644 --- a/newlib/libc/ctype/jp2uc.c +++ b/newlib/libc/ctype/jp2uc.c @@ -166,7 +166,8 @@ __uc2jp (wint_t c, int type) wint_t _jp2uc_l (wint_t c, struct __locale_t * l) { - const char * cs = l ? __locale_charset(l) : __current_locale_charset(); + const char *cs = (l && l != LC_GLOBAL_LOCALE) + ? __locale_charset(l) : __current_locale_charset(); if (0 == strcmp (cs, "JIS")) c = __jp2uc (c, JP_JIS); else if (0 == strcmp (cs, "SJIS")) @@ -179,14 +180,15 @@ _jp2uc_l (wint_t c, struct __locale_t * l) wint_t _jp2uc (wint_t c) { - return _jp2uc_l (c, 0); + return _jp2uc_l (c, NULL); } /* Unicode to Japanese conversion interface */ wint_t _uc2jp_l (wint_t c, struct __locale_t * l) { - const char * cs = l ? __locale_charset(l) : __current_locale_charset(); + const char *cs = (l && l != LC_GLOBAL_LOCALE) + ? __locale_charset(l) : __current_locale_charset(); if (0 == strcmp (cs, "JIS")) c = __uc2jp (c, JP_JIS); else if (0 == strcmp (cs, "SJIS")) |
