From: Benno Rice Date: Tue, 2 Sep 2008 11:27:02 +0000 (+1000) Subject: Checkpoint. Broken. X-Git-Tag: SQUID_3_1_0_1~49^2~62^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bf956b0af1e8bd53ca530531cbc45f8ff3dca40f;p=thirdparty%2Fsquid.git Checkpoint. Broken. --- diff --git a/src/Server.cc b/src/Server.cc index 2ec77c2efd..3c5f0ba3e1 100644 --- a/src/Server.cc +++ b/src/Server.cc @@ -404,17 +404,17 @@ sameUrlHosts(const char *url1, const char *url2) static void purgeEntriesByHeader(const HttpRequest *req, const char *reqUrl, HttpMsg *rep, http_hdr_type hdr) { - const char *url, *absUrl; + const char *hdrUrl, *absUrl; - if ((url = rep->header.getStr(hdr)) != NULL) { - absUrl = urlAbsolute(req, url); + if ((hdrUrl = rep->header.getStr(hdr)) != NULL) { + absUrl = urlMakeAbsolute(req, hdrUrl); if (absUrl != NULL) { - url = absUrl; + hdrUrl = absUrl; } if (absUrl != NULL) { // if the URL was relative, it is by nature the same host - purgeEntriesByUrl(url); - } else if (sameUrlHosts(reqUrl, url)) { // prevent purging DoS, per RFC 2616 13.10, second last paragraph - purgeEntriesByUrl(url); + purgeEntriesByUrl(hdrUrl); + } else if (sameUrlHosts(reqUrl, hdrUrl)) { // prevent purging DoS, per RFC 2616 13.10, second last paragraph + purgeEntriesByUrl(hdrUrl); } if (absUrl != NULL) { safe_free(absUrl); diff --git a/src/protos.h b/src/protos.h index 71f9fadee1..48f1694704 100644 --- a/src/protos.h +++ b/src/protos.h @@ -638,7 +638,8 @@ SQUIDCEXTERN protocol_t urlParseProtocol(const char *, const char *e = NULL); SQUIDCEXTERN void urlInitialize(void); SQUIDCEXTERN HttpRequest *urlParse(const HttpRequestMethod&, char *, HttpRequest *request = NULL); SQUIDCEXTERN const char *urlCanonical(HttpRequest *); -SQUIDCEXTERN const char *urlAbsolute(const HttpRequest *, const char *); +SQUIDCEXTERN int urlIsRelative(const char *); +SQUIDCEXTERN const char *urlMakeAbsolute(const HttpRequest *, const char *); SQUIDCEXTERN char *urlRInternal(const char *host, u_short port, const char *dir, const char *name); SQUIDCEXTERN char *urlInternal(const char *dir, const char *name); SQUIDCEXTERN int matchDomainName(const char *host, const char *domain); diff --git a/src/url.cc b/src/url.cc index 9fb514047a..d6475977ca 100644 --- a/src/url.cc +++ b/src/url.cc @@ -532,20 +532,48 @@ urlCanonicalClean(const HttpRequest * request) return buf; } +/* + * Test if a URL is relative. + * + * RFC 1808 says that colons can show up in 'fragments' or 'queries'. + * Fragments come after a '#' and queries come after '?'. + */ +int +urlIsRelative(const char *url) +{ + const char *p; + + if (url == NULL) { + return (0); + } + if (*url == '\0') { + return (0); + } + + for (p = url; *p != '\0' && *p != ':' && *p != '#' && *p != '?'; p++); + + if (*p == ':') { + return (1); + } + return (0); +} + +/* + * Take a potentially relative URL. If the URL is _not_ relative, return NULL. + * If the URL is relative, generate an absolute URL based on the provided + * request. + */ const char * -urlAbsolute(const HttpRequest * req, const char *relUrl) +urlMakeAbsolute(const HttpRequest * req, const char *relUrl) { char *urlbuf; const char *path, *last_slash; size_t urllen, pathlen; - if (relUrl == NULL) { - return (NULL); - } if (req->method.id() == METHOD_CONNECT) { return (NULL); } - if (strchr(relUrl, ':') != NULL) { + if (!urlIsRelative(relUrl)) { return (NULL); } urlbuf = (char *)xmalloc(MAX_URL * sizeof(char));