Add OPENSSL_str[n]casecmp
Windows has different names for these functions and also doesn't have
the strings.h header in which they appear.
This change adds tiny wrapper functions for Windows.
diff --git a/crypto/mem.c b/crypto/mem.c
index c2fd5fc..9cf0aa0 100644
--- a/crypto/mem.c
+++ b/crypto/mem.c
@@ -135,6 +135,28 @@
return len;
}
+#if defined(OPENSSL_WINDOWS)
+
+int OPENSSL_strcasecmp(const char *a, const char *b) {
+ return _stricmp(a, b, n);
+}
+
+int OPENSSL_strncasecmp(const char *a, const char *b, size_t n) {
+ return _strnicmp(a, b, n);
+}
+
+#else
+
+int OPENSSL_strcasecmp(const char *a, const char *b) {
+ return strcasecmp(a, b);
+}
+
+int OPENSSL_strncasecmp(const char *a, const char *b, size_t n) {
+ return strncasecmp(a, b, n);
+}
+
+#endif
+
int BIO_snprintf(char *buf, size_t n, const char *format, ...) {
va_list args;
int ret;
diff --git a/crypto/mem.h b/crypto/mem.h
index 1a7effd..0d04c95 100644
--- a/crypto/mem.h
+++ b/crypto/mem.h
@@ -100,6 +100,12 @@
/* OPENSSL_strnlen has the same behaviour as strnlen(3). */
size_t OPENSSL_strnlen(const char *s, size_t len);
+/* OPENSSL_strcasecmp has the same behaviour as strcasecmp(3). */
+int OPENSSL_strcasecmp(const char *a, const char *b);
+
+/* OPENSSL_strncasecmp has the same behaviour as strncasecmp(3). */
+int OPENSSL_strncasecmp(const char *a, const char *b, size_t n);
+
/* DECIMAL_SIZE returns an upper bound for the length of the decimal
* representation of the given type. */
#define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1)
diff --git a/crypto/x509v3/v3_ncons.c b/crypto/x509v3/v3_ncons.c
index a9f609f..2fb8c98 100644
--- a/crypto/x509v3/v3_ncons.c
+++ b/crypto/x509v3/v3_ncons.c
@@ -65,10 +65,6 @@
#include <openssl/obj.h>
#include <openssl/x509v3.h>
-#if !defined(OPENSSL_WINDOWS)
-#include <strings.h>
-#endif
-
static void *v2i_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method,
X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
@@ -414,7 +410,7 @@
return X509_V_ERR_PERMITTED_VIOLATION;
}
- if (strcasecmp(baseptr, dnsptr))
+ if (OPENSSL_strcasecmp(baseptr, dnsptr))
return X509_V_ERR_PERMITTED_VIOLATION;
return X509_V_OK;
@@ -436,7 +432,7 @@
if (eml->length > base->length)
{
emlptr += eml->length - base->length;
- if (!strcasecmp(baseptr, emlptr))
+ if (!OPENSSL_strcasecmp(baseptr, emlptr))
return X509_V_OK;
}
return X509_V_ERR_PERMITTED_VIOLATION;
@@ -459,7 +455,7 @@
}
emlptr = emlat + 1;
/* Just have hostname left to match: case insensitive */
- if (strcasecmp(baseptr, emlptr))
+ if (OPENSSL_strcasecmp(baseptr, emlptr))
return X509_V_ERR_PERMITTED_VIOLATION;
return X509_V_OK;
@@ -500,13 +496,13 @@
if (hostlen > base->length)
{
p = hostptr + hostlen - base->length;
- if (!strncasecmp(p, baseptr, base->length))
+ if (!OPENSSL_strncasecmp(p, baseptr, base->length))
return X509_V_OK;
}
return X509_V_ERR_PERMITTED_VIOLATION;
}
- if ((base->length != (int)hostlen) || strncasecmp(hostptr, baseptr, hostlen))
+ if ((base->length != (int)hostlen) || OPENSSL_strncasecmp(hostptr, baseptr, hostlen))
return X509_V_ERR_PERMITTED_VIOLATION;
return X509_V_OK;
diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c
index f3d9269..3bbc606 100644
--- a/crypto/x509v3/v3_utl.c
+++ b/crypto/x509v3/v3_utl.c
@@ -60,7 +60,6 @@
#include <ctype.h>
#include <stdio.h>
-#include <strings.h>
#include <openssl/bn.h>
#include <openssl/buf.h>
@@ -718,7 +717,7 @@
}
/* IDNA labels cannot match partial wildcards */
if (!allow_idna &&
- subject_len >= 4 && strncasecmp((char *)subject, "xn--", 4) == 0)
+ subject_len >= 4 && OPENSSL_strncasecmp((char *)subject, "xn--", 4) == 0)
return 0;
/* The wildcard may match a literal '*' */
if (wildcard_end == wildcard_start + 1 && *wildcard_start == '*')
@@ -784,7 +783,7 @@
* IDNA label state
*/
if ((state & LABEL_IDNA) == 0 && len - i >= 4
- && strncasecmp((char *)&p[i], "xn--", 4) == 0)
+ && OPENSSL_strncasecmp((char *)&p[i], "xn--", 4) == 0)
{
i += 3;
state |= LABEL_IDNA;