diff options
author | Tomas Mraz <tomas@openssl.org> | 2022-05-10 17:00:26 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-05-13 08:33:50 +0200 |
commit | 84b9fe9293e5e37525e86714d6c2568539babbfb (patch) | |
tree | 5e9f0c91385275b17705455b0e65da4e9f4a2ebd /crypto/o_str.c | |
parent | f3da979ee199bff139a643a16636c8c8e36a3f79 (diff) |
Add fallback in case of locale initialization failure
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18293)
Diffstat (limited to 'crypto/o_str.c')
-rw-r--r-- | crypto/o_str.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/crypto/o_str.c b/crypto/o_str.c index 9309a7bad4..f59e324cfa 100644 --- a/crypto/o_str.c +++ b/crypto/o_str.c @@ -349,8 +349,8 @@ int openssl_strerror_r(int errnum, char *buf, size_t buflen) #ifndef OPENSSL_NO_LOCALE static locale_t loc; -static void *ossl_c_locale(void) { - return (void *)loc; +static locale_t ossl_c_locale(void) { + return loc; } int ossl_init_casecmp_int(void) { @@ -359,21 +359,32 @@ int ossl_init_casecmp_int(void) { # else loc = newlocale(LC_COLLATE_MASK, "C", (locale_t) 0); # endif - return (loc == (locale_t) 0) ? 0 : 1; + return (loc == (locale_t)0) ? 0 : 1; } void ossl_deinit_casecmp(void) { freelocale(loc); + loc = (locale_t)0; } int OPENSSL_strcasecmp(const char *s1, const char *s2) { - return strcasecmp_l(s1, s2, (locale_t)ossl_c_locale()); + locale_t l = ossl_c_locale(); + + /* Fallback in case of locale initialization failure */ + if (l == (locale_t)0) + return strcasecmp(s1, s2); + return strcasecmp_l(s1, s2, l); } int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n) { - return strncasecmp_l(s1, s2, n, (locale_t)ossl_c_locale()); + locale_t l = ossl_c_locale(); + + /* Fallback in case of locale initialization failure */ + if (l == (locale_t)0) + return strncasecmp(s1, s2, n); + return strncasecmp_l(s1, s2, n, l); } #else int ossl_init_casecmp_int(void) { |