From a99d905216cc0aac5de0c3050f4afc54e21c6bc5 Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Wed, 5 Oct 2022 10:37:38 -0400 Subject: [PATCH] Bash-5.2 patch 2: fix crash in readline when started with an invalid locale specification --- lib/readline/nls.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/lib/readline/nls.c b/lib/readline/nls.c index d2f67e0..5d1cd19 100644 --- a/lib/readline/nls.c +++ b/lib/readline/nls.c @@ -56,6 +56,8 @@ static int utf8locale PARAMS((char *)); +#define RL_DEFAULT_LOCALE "C" + #if !defined (HAVE_SETLOCALE) /* A list of legal values for the LANG or LC_CTYPE environment variables. If a locale name in this list is the value for the LC_ALL, LC_CTYPE, @@ -136,7 +138,11 @@ _rl_init_locale (void) if (lspec == 0) lspec = ""; ret = setlocale (LC_CTYPE, lspec); /* ok, since it does not change locale */ - + if (ret == 0 || *ret == 0) + ret = setlocale (LC_CTYPE, (char *)NULL); + if (ret == 0 || *ret == 0) + ret = RL_DEFAULT_LOCALE; + _rl_utf8locale = (ret && *ret) ? utf8locale (ret) : 0; return ret; -- 2.35.1