Skip to content

Commit 4ba7eff

Browse files
committed
jp2uc/up2jc: avoid crash due to invalid pointer
Commit 4356ccd ("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: 4356ccd ("towupper/towlower: handle Turkic language special casing") Reported-by: Christophe Lyon <christophe.lyon.oss@gmail.com> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
1 parent 8f1d2b4 commit 4ba7eff

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

newlib/libc/ctype/jp2uc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ __uc2jp (wint_t c, int type)
166166
wint_t
167167
_jp2uc_l (wint_t c, struct __locale_t * l)
168168
{
169-
const char * cs = l ? __locale_charset(l) : __current_locale_charset();
169+
const char *cs = (l && l != LC_GLOBAL_LOCALE)
170+
? __locale_charset(l) : __current_locale_charset();
170171
if (0 == strcmp (cs, "JIS"))
171172
c = __jp2uc (c, JP_JIS);
172173
else if (0 == strcmp (cs, "SJIS"))
@@ -179,14 +180,15 @@ _jp2uc_l (wint_t c, struct __locale_t * l)
179180
wint_t
180181
_jp2uc (wint_t c)
181182
{
182-
return _jp2uc_l (c, 0);
183+
return _jp2uc_l (c, NULL);
183184
}
184185

185186
/* Unicode to Japanese conversion interface */
186187
wint_t
187188
_uc2jp_l (wint_t c, struct __locale_t * l)
188189
{
189-
const char * cs = l ? __locale_charset(l) : __current_locale_charset();
190+
const char *cs = (l && l != LC_GLOBAL_LOCALE)
191+
? __locale_charset(l) : __current_locale_charset();
190192
if (0 == strcmp (cs, "JIS"))
191193
c = __uc2jp (c, JP_JIS);
192194
else if (0 == strcmp (cs, "SJIS"))

0 commit comments

Comments
 (0)