summaryrefslogtreecommitdiffstats
path: root/crypto/o_str.c
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2022-05-10 17:22:24 +0200
committerTomas Mraz <tomas@openssl.org>2022-05-13 08:33:50 +0200
commit932534e7ef11ad43100ea6c81362d1d86e156167 (patch)
tree995a3d3e6b3738080e4df7a6c542189d304a57b7 /crypto/o_str.c
parent84b9fe9293e5e37525e86714d6c2568539babbfb (diff)
Always try locale initialization from OPENSSL_strcasecmp
Fixes #18172 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.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/crypto/o_str.c b/crypto/o_str.c
index f59e324cfa..789de7bd4d 100644
--- a/crypto/o_str.c
+++ b/crypto/o_str.c
@@ -18,6 +18,7 @@
#endif
#include <openssl/crypto.h>
#include "internal/cryptlib.h"
+#include "internal/thread_once.h"
#define DEFAULT_SEPARATOR ':'
#define CH_ZERO '\0'
@@ -347,13 +348,36 @@ int openssl_strerror_r(int errnum, char *buf, size_t buflen)
}
#ifndef OPENSSL_NO_LOCALE
+# ifndef FIPS_MODULE
+static CRYPTO_ONCE casecmp = CRYPTO_ONCE_STATIC_INIT;
+DEFINE_RUN_ONCE_STATIC(init_casecmp)
+{
+ int ret = ossl_init_casecmp_int();
+
+ return ret;
+}
+
+int ossl_init_casecmp(void)
+{
+ if (!RUN_ONCE(&casecmp, init_casecmp))
+ return 0;
+ return 1;
+}
+# endif
+
static locale_t loc;
-static locale_t ossl_c_locale(void) {
+static locale_t ossl_c_locale(void)
+{
+# ifndef FIPS_MODULE
+ if (!ossl_init_casecmp())
+ return (locale_t)0;
+# endif
return loc;
}
-int ossl_init_casecmp_int(void) {
+int ossl_init_casecmp_int(void)
+{
# ifdef OPENSSL_SYS_WINDOWS
loc = _create_locale(LC_COLLATE, "C");
# else
@@ -362,9 +386,12 @@ int ossl_init_casecmp_int(void) {
return (loc == (locale_t)0) ? 0 : 1;
}
-void ossl_deinit_casecmp(void) {
- freelocale(loc);
- loc = (locale_t)0;
+void ossl_deinit_casecmp(void)
+{
+ if (loc != (locale_t)0) {
+ freelocale(loc);
+ loc = (locale_t)0;
+ }
}
int OPENSSL_strcasecmp(const char *s1, const char *s2)
@@ -387,11 +414,18 @@ int OPENSSL_strncasecmp(const char *s1, const char *s2, size_t n)
return strncasecmp_l(s1, s2, n, l);
}
#else
-int ossl_init_casecmp_int(void) {
+int ossl_init_casecmp(void)
+{
return 1;
}
-void ossl_deinit_casecmp(void) {
+int ossl_init_casecmp_int(void)
+{
+ return 1;
+}
+
+void ossl_deinit_casecmp(void)
+{
}
int OPENSSL_strcasecmp(const char *s1, const char *s2)