~yadi/squid/parser-ng-bug2043

« back to all changes in this revision

Viewing changes to src/http/one/Parser.cc

  • Committer: Amos Jeffries
  • Date: 2015-02-28 00:40:23 UTC
  • mfrom: (13924.1.33 trunk)
  • Revision ID: squid3@treenet.co.nz-20150228004023-1bv4uyhwp3n3d57w
Merged from trunk rev.13957

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include "squid.h"
10
10
#include "Debug.h"
11
11
#include "http/one/Parser.h"
 
12
#include "mime_header.h"
12
13
#include "parser/Tokenizer.h"
13
14
#include "SquidConfig.h"
14
15
 
37
38
    return false;
38
39
}
39
40
 
 
41
bool
 
42
Http::One::Parser::grabMimeBlock(const char *which, const size_t limit)
 
43
{
 
44
    // MIME headers block exist in (only) HTTP/1.x and ICY
 
45
    const bool expectMime = (msgProtocol_.protocol == AnyP::PROTO_HTTP && msgProtocol_.major == 1) ||
 
46
                            msgProtocol_.protocol == AnyP::PROTO_ICY;
 
47
 
 
48
    if (expectMime) {
 
49
        /* NOTE: HTTP/0.9 messages do not have a mime header block.
 
50
         *       So the rest of the code will need to deal with '0'-byte headers
 
51
         *       (ie, none, so don't try parsing em)
 
52
         */
 
53
        // XXX: c_str() reallocates. performance regression.
 
54
        if (SBuf::size_type mimeHeaderBytes = headersEnd(buf_.c_str(), buf_.length())) {
 
55
 
 
56
            // Squid could handle these headers, but admin does not want to
 
57
            if (firstLineSize() + mimeHeaderBytes >= limit) {
 
58
                debugs(33, 5, "Too large " << which);
 
59
                parseStatusCode = Http::scHeaderTooLarge;
 
60
                buf_.consume(mimeHeaderBytes);
 
61
                parsingStage_ = HTTP_PARSE_DONE;
 
62
                return false;
 
63
            }
 
64
 
 
65
            mimeHeaderBlock_ = buf_.consume(mimeHeaderBytes);
 
66
            debugs(74, 5, "mime header (0-" << mimeHeaderBytes << ") {" << mimeHeaderBlock_ << "}");
 
67
 
 
68
        } else { // headersEnd() == 0
 
69
            if (buf_.length()+firstLineSize() >= limit) {
 
70
                debugs(33, 5, "Too large " << which);
 
71
                parseStatusCode = Http::scHeaderTooLarge;
 
72
                parsingStage_ = HTTP_PARSE_DONE;
 
73
            } else
 
74
                debugs(33, 5, "Incomplete " << which << ", waiting for end of headers");
 
75
            return false;
 
76
        }
 
77
 
 
78
    } else
 
79
        debugs(33, 3, "Missing HTTP/1.x identifier");
 
80
 
 
81
    // NP: we do not do any further stages here yet so go straight to DONE
 
82
    parsingStage_ = HTTP_PARSE_DONE;
 
83
 
 
84
    return true;
 
85
}
 
86
 
40
87
// arbitrary maximum-length for headers which can be found by Http1Parser::getHeaderField()
41
88
#define GET_HDR_SZ  1024
42
89