From: Amos Jeffries Date: Thu, 31 Mar 2011 22:47:06 +0000 (-0600) Subject: Default constructor for HttpParser X-Git-Tag: take06~27^2~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=24a59c1f51e24d2b9c04f853f6e38626b243ef95;p=thirdparty%2Fsquid.git Default constructor for HttpParser rev11314 added an no-op default constructor. But that could allow creation with broken state. Add a clear() function to perform the default constructor initialization. That can also be shared by the other init code. --- diff --git a/src/HttpMsg.cc b/src/HttpMsg.cc index 7f1db0176f..874a1a3221 100644 --- a/src/HttpMsg.cc +++ b/src/HttpMsg.cc @@ -379,17 +379,11 @@ HttpMsg::_unlock() void HttpParserInit(HttpParser *hdr, const char *buf, int bufsiz) { + hdr->clear(); hdr->state = 1; - hdr->request_parse_status = HTTP_STATUS_NONE; hdr->buf = buf; hdr->bufsiz = bufsiz; - hdr->req_start = hdr->req_end = -1; - hdr->hdr_start = hdr->hdr_end = -1; debugs(74, 5, "httpParseInit: Request buffer is " << buf); - hdr->m_start = hdr->m_end = -1; - hdr->u_start = hdr->u_end = -1; - hdr->v_start = hdr->v_end = -1; - hdr->v_maj = hdr->v_min = 0; } #if MSGDODEBUG @@ -439,6 +433,21 @@ HttpParser::HttpParser(const char *buf, int len) HttpParserInit(this, buf, len); } +void +HttpParser::clear() +{ + state = 0; + request_parse_status = HTTP_STATUS_NONE; + buf = NULL; // NP: we do not own the buffer, merely reference to it. + bufsiz = 0; + req_start = req_end = -1; + hdr_start = hdr_end = -1; + m_start = m_end = -1; + u_start = u_end = -1; + v_start = v_end = -1; + v_maj = v_min = 0; +} + int HttpParser::parseRequestFirstLine() { diff --git a/src/HttpMsg.h b/src/HttpMsg.h index 72a932473c..37f1307f0f 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -136,9 +136,13 @@ protected: class HttpParser { public: - HttpParser() {}; + HttpParser() { clear(); } HttpParser(const char *buf, int len); + /// Set this parser back to a default state. + /// Will DROP any reference to a buffer (does not free). + void clear(); + /** * Attempt to parse the first line of a new request message. *