aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/hostcheck.c
diff options
context:
space:
mode:
authordeshevoy <deshevoy@yandex-team.ru>2022-02-10 16:46:56 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:56 +0300
commite988f30484abe5fdeedcc7a5d3c226c01a21800c (patch)
tree0a217b173aabb57b7e51f8a169989b1a3e0309fe /contrib/libs/curl/lib/hostcheck.c
parent33ee501c05d3f24036ae89766a858930ae66c548 (diff)
downloadydb-e988f30484abe5fdeedcc7a5d3c226c01a21800c.tar.gz
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/curl/lib/hostcheck.c')
-rw-r--r--contrib/libs/curl/lib/hostcheck.c146
1 files changed, 73 insertions, 73 deletions
diff --git a/contrib/libs/curl/lib/hostcheck.c b/contrib/libs/curl/lib/hostcheck.c
index 4d0614aeab..d0637e1c5a 100644
--- a/contrib/libs/curl/lib/hostcheck.c
+++ b/contrib/libs/curl/lib/hostcheck.c
@@ -22,93 +22,93 @@
#include "curl_setup.h"
-#if defined(USE_OPENSSL) \
- || defined(USE_GSKIT) \
- || defined(USE_SCHANNEL)
+#if defined(USE_OPENSSL) \
+ || defined(USE_GSKIT) \
+ || defined(USE_SCHANNEL)
/* these backends use functions from this file */
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_NETINET_IN6_H
-#error #include <netinet/in6.h>
-#endif
-
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NETINET_IN6_H
+#error #include <netinet/in6.h>
+#endif
+
#include "hostcheck.h"
-#include "strcase.h"
-#include "inet_pton.h"
-
-#include "curl_memory.h"
-/* The last #include file should be: */
-#include "memdebug.h"
+#include "strcase.h"
+#include "inet_pton.h"
+#include "curl_memory.h"
+/* The last #include file should be: */
+#include "memdebug.h"
+
/*
* Match a hostname against a wildcard pattern.
* E.g.
* "foo.host.com" matches "*.host.com".
*
* We use the matching rule described in RFC6125, section 6.4.3.
- * https://tools.ietf.org/html/rfc6125#section-6.4.3
- *
- * In addition: ignore trailing dots in the host names and wildcards, so that
- * the names are used normalized. This is what the browsers do.
- *
- * Do not allow wildcard matching on IP numbers. There are apparently
- * certificates being used with an IP address in the CN field, thus making no
- * apparent distinction between a name and an IP. We need to detect the use of
- * an IP address and not wildcard match on such names.
- *
- * NOTE: hostmatch() gets called with copied buffers so that it can modify the
- * contents at will.
+ * https://tools.ietf.org/html/rfc6125#section-6.4.3
+ *
+ * In addition: ignore trailing dots in the host names and wildcards, so that
+ * the names are used normalized. This is what the browsers do.
+ *
+ * Do not allow wildcard matching on IP numbers. There are apparently
+ * certificates being used with an IP address in the CN field, thus making no
+ * apparent distinction between a name and an IP. We need to detect the use of
+ * an IP address and not wildcard match on such names.
+ *
+ * NOTE: hostmatch() gets called with copied buffers so that it can modify the
+ * contents at will.
*/
-static int hostmatch(char *hostname, char *pattern)
+static int hostmatch(char *hostname, char *pattern)
{
const char *pattern_label_end, *pattern_wildcard, *hostname_label_end;
int wildcard_enabled;
size_t prefixlen, suffixlen;
- struct in_addr ignored;
-#ifdef ENABLE_IPV6
- struct sockaddr_in6 si6;
-#endif
-
- /* normalize pattern and hostname by stripping off trailing dots */
- size_t len = strlen(hostname);
- if(hostname[len-1]=='.')
- hostname[len-1] = 0;
- len = strlen(pattern);
- if(pattern[len-1]=='.')
- pattern[len-1] = 0;
-
+ struct in_addr ignored;
+#ifdef ENABLE_IPV6
+ struct sockaddr_in6 si6;
+#endif
+
+ /* normalize pattern and hostname by stripping off trailing dots */
+ size_t len = strlen(hostname);
+ if(hostname[len-1]=='.')
+ hostname[len-1] = 0;
+ len = strlen(pattern);
+ if(pattern[len-1]=='.')
+ pattern[len-1] = 0;
+
pattern_wildcard = strchr(pattern, '*');
if(pattern_wildcard == NULL)
- return strcasecompare(pattern, hostname) ?
+ return strcasecompare(pattern, hostname) ?
CURL_HOST_MATCH : CURL_HOST_NOMATCH;
- /* detect IP address as hostname and fail the match if so */
- if(Curl_inet_pton(AF_INET, hostname, &ignored) > 0)
- return CURL_HOST_NOMATCH;
-#ifdef ENABLE_IPV6
- if(Curl_inet_pton(AF_INET6, hostname, &si6.sin6_addr) > 0)
- return CURL_HOST_NOMATCH;
-#endif
-
+ /* detect IP address as hostname and fail the match if so */
+ if(Curl_inet_pton(AF_INET, hostname, &ignored) > 0)
+ return CURL_HOST_NOMATCH;
+#ifdef ENABLE_IPV6
+ if(Curl_inet_pton(AF_INET6, hostname, &si6.sin6_addr) > 0)
+ return CURL_HOST_NOMATCH;
+#endif
+
/* We require at least 2 dots in pattern to avoid too wide wildcard
match. */
wildcard_enabled = 1;
pattern_label_end = strchr(pattern, '.');
- if(pattern_label_end == NULL || strchr(pattern_label_end + 1, '.') == NULL ||
+ if(pattern_label_end == NULL || strchr(pattern_label_end + 1, '.') == NULL ||
pattern_wildcard > pattern_label_end ||
- strncasecompare(pattern, "xn--", 4)) {
+ strncasecompare(pattern, "xn--", 4)) {
wildcard_enabled = 0;
}
if(!wildcard_enabled)
- return strcasecompare(pattern, hostname) ?
+ return strcasecompare(pattern, hostname) ?
CURL_HOST_MATCH : CURL_HOST_NOMATCH;
hostname_label_end = strchr(hostname, '.');
if(hostname_label_end == NULL ||
- !strcasecompare(pattern_label_end, hostname_label_end))
+ !strcasecompare(pattern_label_end, hostname_label_end))
return CURL_HOST_NOMATCH;
/* The wildcard must match at least one character, so the left-most
@@ -118,33 +118,33 @@ static int hostmatch(char *hostname, char *pattern)
return CURL_HOST_NOMATCH;
prefixlen = pattern_wildcard - pattern;
- suffixlen = pattern_label_end - (pattern_wildcard + 1);
- return strncasecompare(pattern, hostname, prefixlen) &&
- strncasecompare(pattern_wildcard + 1, hostname_label_end - suffixlen,
+ suffixlen = pattern_label_end - (pattern_wildcard + 1);
+ return strncasecompare(pattern, hostname, prefixlen) &&
+ strncasecompare(pattern_wildcard + 1, hostname_label_end - suffixlen,
suffixlen) ?
CURL_HOST_MATCH : CURL_HOST_NOMATCH;
}
int Curl_cert_hostcheck(const char *match_pattern, const char *hostname)
{
- int res = 0;
+ int res = 0;
if(!match_pattern || !*match_pattern ||
!hostname || !*hostname) /* sanity check */
- ;
- else {
+ ;
+ else {
char *matchp = strdup(match_pattern);
- if(matchp) {
+ if(matchp) {
char *hostp = strdup(hostname);
- if(hostp) {
- if(hostmatch(hostp, matchp) == CURL_HOST_MATCH)
- res = 1;
- free(hostp);
- }
- free(matchp);
- }
- }
-
- return res;
+ if(hostp) {
+ if(hostmatch(hostp, matchp) == CURL_HOST_MATCH)
+ res = 1;
+ free(hostp);
+ }
+ free(matchp);
+ }
+ }
+
+ return res;
}
-#endif /* OPENSSL, GSKIT or schannel+wince */
+#endif /* OPENSSL, GSKIT or schannel+wince */