diff options
Diffstat (limited to 'libs/libcurl/src/altsvc.c')
-rw-r--r-- | libs/libcurl/src/altsvc.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/libs/libcurl/src/altsvc.c b/libs/libcurl/src/altsvc.c index 36acc3a5ef..dd2d0ebed6 100644 --- a/libs/libcurl/src/altsvc.c +++ b/libs/libcurl/src/altsvc.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2019 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 2019 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -21,7 +21,7 @@ ***************************************************************************/ /* * The Alt-Svc: header is defined in RFC 7838: - * https://tools.ietf.org/html/rfc7838 + * https://datatracker.ietf.org/doc/html/rfc7838 */ #include "curl_setup.h" @@ -54,6 +54,8 @@ #define H3VERSION "h3-29" #elif defined(USE_NGTCP2) && !defined(UNITTESTS) #define H3VERSION "h3-29" +#elif defined(USE_MSH3) && !defined(UNITTESTS) +#define H3VERSION "h3-29" #else #define H3VERSION "h3" #endif @@ -100,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; @@ -264,7 +271,7 @@ struct altsvcinfo *Curl_altsvc_init(void) /* set default behavior */ asi->flags = CURLALTSVC_H1 -#ifdef USE_NGHTTP2 +#ifdef USE_HTTP2 | CURLALTSVC_H2 #endif #ifdef ENABLE_QUIC @@ -396,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, @@ -408,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); } @@ -633,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 */ |