From commits-return-4230-apmail-trafficserver-commits-archive=trafficserver.apache.org@trafficserver.apache.org Thu Feb 2 01:34:58 2012 Return-Path: X-Original-To: apmail-trafficserver-commits-archive@www.apache.org Delivered-To: apmail-trafficserver-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B3D499C81 for ; Thu, 2 Feb 2012 01:34:58 +0000 (UTC) Received: (qmail 21838 invoked by uid 500); 2 Feb 2012 01:34:58 -0000 Delivered-To: apmail-trafficserver-commits-archive@trafficserver.apache.org Received: (qmail 21794 invoked by uid 500); 2 Feb 2012 01:34:57 -0000 Mailing-List: contact commits-help@trafficserver.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@trafficserver.apache.org Delivered-To: mailing list commits@trafficserver.apache.org Received: (qmail 21787 invoked by uid 99); 2 Feb 2012 01:34:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Feb 2012 01:34:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.114] (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Feb 2012 01:34:55 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 561EB31B3A3; Thu, 2 Feb 2012 01:34:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: amc@apache.org To: commits@trafficserver.apache.org X-Mailer: ASF-Git Admin Mailer Subject: git commit: TS-1094: Handle buffer with just CR in it correctly for MIME parsing. Message-Id: <20120202013435.561EB31B3A3@tyr.zones.apache.org> Date: Thu, 2 Feb 2012 01:34:35 +0000 (UTC) Updated Branches: refs/heads/master 498003b5e -> b55801c81 TS-1094: Handle buffer with just CR in it correctly for MIME parsing. Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/b55801c8 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/b55801c8 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/b55801c8 Branch: refs/heads/master Commit: b55801c814dff141b3d287f42e943e21a850a993 Parents: 498003b Author: Alan M. Carroll Authored: Wed Feb 1 10:51:02 2012 -0600 Committer: Alan M. Carroll Committed: Wed Feb 1 19:19:38 2012 -0600 ---------------------------------------------------------------------- proxy/hdrs/MIME.cc | 34 ++++++++++++++++++++++++++++++---- proxy/hdrs/MIME.h | 1 + 2 files changed, 31 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b55801c8/proxy/hdrs/MIME.cc ---------------------------------------------------------------------- diff --git a/proxy/hdrs/MIME.cc b/proxy/hdrs/MIME.cc index e2e3cbb..2fa5f66 100644 --- a/proxy/hdrs/MIME.cc +++ b/proxy/hdrs/MIME.cc @@ -2196,6 +2196,8 @@ mime_scanner_get(MIMEScanner *S, { const char *raw_input_c, *lf_ptr; MIMEParseResult zret = PARSE_CONT; + // Need this for handling dangling CR. + static char const RAW_CR = ParseRules::CHAR_CR; ink_debug_assert((raw_input_s != NULL) && (*raw_input_s != NULL)); ink_debug_assert(raw_input_e != NULL); @@ -2206,11 +2208,35 @@ mime_scanner_get(MIMEScanner *S, ptrdiff_t runway = raw_input_e - raw_input_c; // remaining input. switch (S->m_state) { case MIME_PARSE_BEFORE: // waiting to find a field. - // If we find leading CR LF then it's the last line of the header. - if (ParseRules::is_cr(*raw_input_c) && runway >= 2 && ParseRules::is_lf(raw_input_c[1])) { - raw_input_c += 2; - zret = PARSE_OK; + if (ParseRules::is_cr(*raw_input_c)) { + ++raw_input_c; + if (runway >= 2 && ParseRules::is_lf(*raw_input_c)) { + // optimize a bit - this happens >99% of the time after a CR. + ++raw_input_c; + zret = PARSE_DONE; + } else { + S->m_state = MIME_PARSE_FOUND_CR; + } + } else if (ParseRules::is_lf(*raw_input_c)) { + ++raw_input_c; + zret = PARSE_DONE; // Required by regression test. + } else { + // consume this character in the next state. + S->m_state = MIME_PARSE_INSIDE; + } + break; + case MIME_PARSE_FOUND_CR: + // Looking for a field and found a CR, which should mean terminating + // the header. Note that we've left the CR in the input so we have + // to skip over it. + if (ParseRules::is_lf(*raw_input_c)) { + // Header terminated. + ++raw_input_c; + zret = PARSE_DONE; } else { + // This really should be an error (spec doesn't permit lone CR) + // but the regression tests require it. + mime_scanner_append(S, &RAW_CR, 1); S->m_state = MIME_PARSE_INSIDE; } break; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b55801c8/proxy/hdrs/MIME.h ---------------------------------------------------------------------- diff --git a/proxy/hdrs/MIME.h b/proxy/hdrs/MIME.h index 5af9e09..49a6b98 100644 --- a/proxy/hdrs/MIME.h +++ b/proxy/hdrs/MIME.h @@ -55,6 +55,7 @@ enum /// Parsing state. enum MimeParseState { MIME_PARSE_BEFORE, ///< Before a field. + MIME_PARSE_FOUND_CR, ///< Before a field, found a CR. MIME_PARSE_INSIDE, ///< Inside a field. MIME_PARSE_AFTER, ///< After a field. };