vport = conn->clientConnection->local.port();
char *host = NULL;
- if (vhost && (host = hp->getHeaderField("Host"))) {
+ if (vhost && (host = hp->getHostHeaderField())) {
debugs(33, 5, "ACCEL VHOST REWRITE: vhost=" << host << " + vport=" << vport);
char thost[256];
if (vport > 0) {
{
char *uri = nullptr;
/* BUG: Squid cannot deal with '*' URLs (RFC2616 5.1.2) */
- if (const char *host = hp->getHeaderField("Host")) {
+ if (const char *host = hp->getHostHeaderField()) {
const SBuf &scheme = AnyP::UriScheme(conn->transferProtocol.protocol).image();
const int url_sz = scheme.length() + strlen(host) + hp->requestUri().length() + 32;
uri = static_cast<char *>(xcalloc(url_sz, 1));
return true;
}
-// arbitrary maximum-length for headers which can be found by Http1Parser::getHeaderField()
+// arbitrary maximum-length for headers which can be found by Http1Parser::getHostHeaderField()
#define GET_HDR_SZ 1024
// BUG: returns only the first header line with given name,
// ignores multi-line headers and obs-fold headers
char *
-Http::One::Parser::getHeaderField(const char *name)
+Http::One::Parser::getHostHeaderField()
{
- if (!headerBlockSize() || !name)
+ if (!headerBlockSize())
return NULL;
LOCAL_ARRAY(char, header, GET_HDR_SZ);
+ const char *name = "Host";
const int namelen = strlen(name);
debugs(25, 5, "looking for " << name);
// prevent buffer overrun on char header[];
p.chop(0, sizeof(header)-1);
+ // currently only used for pre-parse Host header, ensure valid domain[:port] or ip[:port]
+ static const auto hostChars = CharacterSet("host",":[].-_") + CharacterSet::ALPHA + CharacterSet::DIGIT;
+ if (p.findFirstNotOf(hostChars) != SBuf::npos)
+ break; // error. line contains character not accepted in Host header
+
// return the header field-value
SBufToCstring(header, p);
debugs(25, 5, "returning " << header);
const AnyP::ProtocolVersion & messageProtocol() const {return msgProtocol_;}
/**
- * Scan the mime header block (badly) for a header with the given name.
+ * Scan the mime header block (badly) for a Host header.
*
* BUG: omits lines when searching for headers with obs-fold or multiple entries.
*
*
* \return A pointer to a field-value of the first matching field-name, or NULL.
*/
- char *getHeaderField(const char *name);
+ char *getHostHeaderField();
/// the remaining unprocessed section of buffer
const SBuf &remaining() const {return buf_;}