summaryrefslogtreecommitdiffstats
path: root/Utilities/cmcurl/lib/altsvc.c
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-05-16 15:43:51 (GMT)
committerBrad King <brad.king@kitware.com>2022-05-16 15:43:51 (GMT)
commit71747a28ea56d8e2f86759176c15fc1e56f5f605 (patch)
treee49f7f73e1b16cdc08f05666cd5e3089584b493d /Utilities/cmcurl/lib/altsvc.c
parent02902188ecfb85824c4bea56c2d3262791adbda9 (diff)
parent9d8f81f4f8ac4a234ced9c446958fdfcaed4faa3 (diff)
downloadCMake-71747a28ea56d8e2f86759176c15fc1e56f5f605.zip
CMake-71747a28ea56d8e2f86759176c15fc1e56f5f605.tar.gz
CMake-71747a28ea56d8e2f86759176c15fc1e56f5f605.tar.bz2
Merge branch 'upstream-curl' into update-curl
* upstream-curl: curl 2022-05-11 (462196e6)
Diffstat (limited to 'Utilities/cmcurl/lib/altsvc.c')
-rw-r--r--Utilities/cmcurl/lib/altsvc.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/Utilities/cmcurl/lib/altsvc.c b/Utilities/cmcurl/lib/altsvc.c
index 45929a5..dd2d0eb 100644
--- a/Utilities/cmcurl/lib/altsvc.c
+++ b/Utilities/cmcurl/lib/altsvc.c
@@ -102,12 +102,17 @@ static struct altsvc *altsvc_createid(const char *srchost,
unsigned int dstport)
{
struct altsvc *as = calloc(sizeof(struct altsvc), 1);
+ size_t hlen;
if(!as)
return NULL;
-
+ hlen = strlen(srchost);
+ DEBUGASSERT(hlen);
as->src.host = strdup(srchost);
if(!as->src.host)
goto error;
+ if(hlen && (srchost[hlen - 1] == '.'))
+ /* strip off trailing any dot */
+ as->src.host[--hlen] = 0;
as->dst.host = strdup(dsthost);
if(!as->dst.host)
goto error;
@@ -398,6 +403,22 @@ static CURLcode getalnum(const char **ptr, char *alpnbuf, size_t buflen)
return CURLE_OK;
}
+/* hostcompare() returns true if 'host' matches 'check'. The first host
+ * argument may have a trailing dot present that will be ignored.
+ */
+static bool hostcompare(const char *host, const char *check)
+{
+ size_t hlen = strlen(host);
+ size_t clen = strlen(check);
+
+ if(hlen && (host[hlen - 1] == '.'))
+ hlen--;
+ if(hlen != clen)
+ /* they can't match if they have different lengths */
+ return FALSE;
+ return strncasecompare(host, check, hlen);
+}
+
/* altsvc_flush() removes all alternatives for this source origin from the
list */
static void altsvc_flush(struct altsvcinfo *asi, enum alpnid srcalpnid,
@@ -410,7 +431,7 @@ static void altsvc_flush(struct altsvcinfo *asi, enum alpnid srcalpnid,
n = e->next;
if((srcalpnid == as->src.alpnid) &&
(srcport == as->src.port) &&
- strcasecompare(srchost, as->src.host)) {
+ hostcompare(srchost, as->src.host)) {
Curl_llist_remove(&asi->list, e, NULL);
altsvc_free(as);
}
@@ -635,7 +656,7 @@ bool Curl_altsvc_lookup(struct altsvcinfo *asi,
continue;
}
if((as->src.alpnid == srcalpnid) &&
- strcasecompare(as->src.host, srchost) &&
+ hostcompare(srchost, as->src.host) &&
(as->src.port == srcport) &&
(versions & as->dst.alpnid)) {
/* match */