41a6c3
41a6c3
https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2016-8743
41a6c3
41a6c3
diff -uap httpd-2.4.6/docs/manual/mod/core.html.en.cve8743 httpd-2.4.6/docs/manual/mod/core.html.en
41a6c3
--- httpd-2.4.6/docs/manual/mod/core.html.en.cve8743
41a6c3
+++ httpd-2.4.6/docs/manual/mod/core.html.en
41a6c3
@@ -67,6 +67,7 @@
41a6c3
 
  • ForceType
  • 41a6c3
     
  • GprofDir
  • 41a6c3
     
  • HostnameLookups
  • 41a6c3
    +
  • HttpProtocolOptions
  • 41a6c3
     
  • <If>
  • 41a6c3
     
  • <IfDefine>
  • 41a6c3
     
  • <IfModule>
  • 41a6c3
    @@ -93,6 +94,7 @@
    41a6c3
     
  • NameVirtualHost
  • 41a6c3
     
  • Options
  • 41a6c3
     
  • Protocol
  • 41a6c3
    +
  • RegisterHttpMethod
  • 41a6c3
     
  • RLimitCPU
  • 41a6c3
     
  • RLimitMEM
  • 41a6c3
     
  • RLimitNPROC
  • 41a6c3
    @@ -1918,6 +1920,74 @@
    41a6c3
     
    41a6c3
     
    41a6c3
     
    top
    41a6c3
    +
    41a6c3
    +
    41a6c3
    +Description:Modify restrictions on HTTP Request Messages
    41a6c3
    +Syntax:HttpProtocolOptions [Strict|Unsafe] [RegisteredMethods|LenientMethods]
    41a6c3
    + [Allow0.9|Require1.0]
    41a6c3
    +Default:HttpProtocolOptions Strict LenientMethods Allow0.9
    41a6c3
    +Context:server config, virtual host
    41a6c3
    +Status:Core
    41a6c3
    +Module:core
    41a6c3
    +Compatibility:2.2.32 or 2.4.24 and later
    41a6c3
    +
    41a6c3
    +    

    This directive changes the rules applied to the HTTP Request Line

    41a6c3
    +    (RFC 7230 §3.1.1) and the HTTP Request Header Fields
    41a6c3
    +    (RFC 7230 §3.2), which are now applied by default or using
    41a6c3
    +    the Strict option. Due to legacy modules, applications or
    41a6c3
    +    custom user-agents which must be deperecated the Unsafe
    41a6c3
    +    option has been added to revert to the legacy behaviors. These rules
    41a6c3
    +    are applied prior to request processing, so must be configured at the
    41a6c3
    +    global or default (first) matching virtual host section, by IP/port
    41a6c3
    +    interface (and not by name) to be honored.

    41a6c3
    +
    41a6c3
    +    

    Prior to the introduction of this directive, the Apache HTTP Server

    41a6c3
    +    request message parsers were tolerant of a number of forms of input
    41a6c3
    +    which did not conform to the protocol.
    41a6c3
    +    RFC 7230 §9.4 Request Splitting and
    41a6c3
    +    §9.5 Response Smuggling call out only two of the potential
    41a6c3
    +    risks of accepting non-conformant request messages, while
    41a6c3
    +    RFC 7230 §3.5 "Message Parsing Robustness" identify the
    41a6c3
    +    risks of accepting obscure whitespace and request message formatting. 
    41a6c3
    +    As of the introduction of this directive, all grammer rules of the
    41a6c3
    +    specification are enforced in the default Strict operating
    41a6c3
    +    mode, and the strict whitespace suggested by section 3.5 is enforced
    41a6c3
    +    and cannot be relaxed.

    41a6c3
    +
    41a6c3
    +    

    Users are strongly cautioned against toggling the Unsafe

    41a6c3
    +    mode of operation, particularly on outward-facing, publicly accessible
    41a6c3
    +    server deployments.  If an interface is required for faulty monitoring
    41a6c3
    +    or other custom service consumers running on an intranet, users should
    41a6c3
    +    toggle the Unsafe option only on a specific virtual host configured
    41a6c3
    +    to service their internal private network.

    41a6c3
    +
    41a6c3
    +    

    Reviewing the messages logged to the ErrorLog,

    41a6c3
    +    configured with LogLevel debug level,
    41a6c3
    +    can help identify such faulty requests along with their origin.
    41a6c3
    +    Users should pay particular attention to the 400 responses in the access
    41a6c3
    +    log for invalid requests which were unexpectedly rejected.

    41a6c3
    +
    41a6c3
    +    

    RFC 7231 §4.1 "Request Methods" "Overview" requires that

    41a6c3
    +    origin servers shall respond with an error when an unsupported method
    41a6c3
    +    is encountered in the request line. This already happens when the
    41a6c3
    +    LenientMethods option is used, but administrators may wish
    41a6c3
    +    to toggle the RegisteredMethods option and register any
    41a6c3
    +    non-standard methods using the RegisterHttpMethod
    41a6c3
    +    directive, particularly if the Unsafe option has been toggled.
    41a6c3
    +    The RegisteredMethods option should not
    41a6c3
    +    be toggled for forward proxy hosts, as the methods supported by the
    41a6c3
    +    origin servers are unknown to the proxy server.

    41a6c3
    +
    41a6c3
    +    

    RFC 2616 §19.6 "Compatibility With Previous Versions" had

    41a6c3
    +    encouraged HTTP servers to support legacy HTTP/0.9 requests. RFC 7230
    41a6c3
    +    superceeds this with "The expectation to support HTTP/0.9 requests has
    41a6c3
    +    been removed" and offers additional comments in 
    41a6c3
    +    RFC 7230 Appendix A. The Require1.0 option allows
    41a6c3
    +    the user to remove support of the default Allow0.9 option's
    41a6c3
    +    behavior.

    41a6c3
    +
    41a6c3
    +
    41a6c3
    +
    top
    41a6c3
     
    41a6c3
     
    41a6c3
     Description:Contains directives that apply only if a condition is
    41a6c3
    @@ -3541,6 +3611,23 @@
    41a6c3
     
    41a6c3
     
    41a6c3
     
    top
    41a6c3
    +
    41a6c3
    +
    41a6c3
    +Description:Register non-standard HTTP methods
    41a6c3
    +Syntax:RegisterHttpMethod method [method [...]]
    41a6c3
    +Context:server config
    41a6c3
    +Status:Core
    41a6c3
    +Module:core
    41a6c3
    +
    41a6c3
    +

    HTTP Methods that are not conforming to the relvant RFCs are normally

    41a6c3
    +rejected by request processing in Apache HTTPD. To avoid this, modules
    41a6c3
    +can register non-standard HTTP methods they support.
    41a6c3
    +The RegisterHttpMethod allows to register such
    41a6c3
    +methods manually. This can be useful for if such methods are forwared
    41a6c3
    +for external processing, e.g. to a CGI script.

    41a6c3
    +
    41a6c3
    +
    41a6c3
    +
    top
    41a6c3
     
    41a6c3
     
    41a6c3
     Description:Limits the CPU consumption of processes launched
    41a6c3
    diff -uap httpd-2.4.6/include/http_core.h.cve8743 httpd-2.4.6/include/http_core.h
    41a6c3
    --- httpd-2.4.6/include/http_core.h.cve8743
    41a6c3
    +++ httpd-2.4.6/include/http_core.h
    41a6c3
    @@ -668,6 +668,21 @@
    41a6c3
     #define AP_MERGE_TRAILERS_DISABLE  2
    41a6c3
         int merge_trailers;
    41a6c3
     
    41a6c3
    +#define AP_HTTP09_UNSET   0
    41a6c3
    +#define AP_HTTP09_ENABLE  1
    41a6c3
    +#define AP_HTTP09_DISABLE 2
    41a6c3
    +    char http09_enable;
    41a6c3
    +
    41a6c3
    +#define AP_HTTP_CONFORMANCE_UNSET     0
    41a6c3
    +#define AP_HTTP_CONFORMANCE_UNSAFE    1
    41a6c3
    +#define AP_HTTP_CONFORMANCE_STRICT    2
    41a6c3
    +    char http_conformance;
    41a6c3
    +
    41a6c3
    +#define AP_HTTP_METHODS_UNSET         0
    41a6c3
    +#define AP_HTTP_METHODS_LENIENT       1
    41a6c3
    +#define AP_HTTP_METHODS_REGISTERED    2
    41a6c3
    +    char http_methods;
    41a6c3
    +
    41a6c3
     } core_server_config;
    41a6c3
     
    41a6c3
     /* for AddOutputFiltersByType in core.c */
    41a6c3
    diff -uap httpd-2.4.6/include/httpd.h.cve8743 httpd-2.4.6/include/httpd.h
    41a6c3
    --- httpd-2.4.6/include/httpd.h.cve8743
    41a6c3
    +++ httpd-2.4.6/include/httpd.h
    41a6c3
    @@ -1584,6 +1584,28 @@
    41a6c3
      */
    41a6c3
     AP_DECLARE(int) ap_unescape_url(char *url);
    41a6c3
     
    41a6c3
    +/* Scan a string for field content chars, as defined by RFC7230 section 3.2
    41a6c3
    + * including VCHAR/obs-text, as well as HT and SP
    41a6c3
    + * @param ptr The string to scan
    41a6c3
    + * @return A pointer to the first (non-HT) ASCII ctrl character.
    41a6c3
    + * @note lws and trailing whitespace are scanned, the caller is responsible
    41a6c3
    + * for trimming leading and trailing whitespace
    41a6c3
    + */
    41a6c3
    +AP_DECLARE(const char *) ap_scan_http_field_content(const char *ptr);
    41a6c3
    +
    41a6c3
    +/* Scan a string for token characters, as defined by RFC7230 section 3.2.6
    41a6c3
    + * @param ptr The string to scan
    41a6c3
    + * @return A pointer to the first non-token character.
    41a6c3
    + */
    41a6c3
    +AP_DECLARE(const char *) ap_scan_http_token(const char *ptr);
    41a6c3
    +
    41a6c3
    +/* Scan a string for visible ASCII (0x21-0x7E) or obstext (0x80+)
    41a6c3
    + * and return a pointer to the first SP/CTL/NUL character encountered.
    41a6c3
    + * @param ptr The string to scan
    41a6c3
    + * @return A pointer to the first SP/CTL character.
    41a6c3
    + */
    41a6c3
    +AP_DECLARE(const char *) ap_scan_vchar_obstext(const char *ptr);
    41a6c3
    +
    41a6c3
     /**
    41a6c3
      * Unescape a URL, but leaving %2f (slashes) escaped
    41a6c3
      * @param url The url to unescape
    41a6c3
    diff -uap httpd-2.4.6/include/http_protocol.h.cve8743 httpd-2.4.6/include/http_protocol.h
    41a6c3
    --- httpd-2.4.6/include/http_protocol.h.cve8743
    41a6c3
    +++ httpd-2.4.6/include/http_protocol.h
    41a6c3
    @@ -582,17 +582,22 @@
    41a6c3
      */
    41a6c3
     AP_CORE_DECLARE(void) ap_parse_uri(request_rec *r, const char *uri);
    41a6c3
     
    41a6c3
    +#define AP_GETLINE_FOLD 1 /* Whether to merge continuation lines */
    41a6c3
    +#define AP_GETLINE_CRLF 2 /*Whether line ends must be in the form CR LF */
    41a6c3
    +
    41a6c3
     /**
    41a6c3
      * Get the next line of input for the request
    41a6c3
      * @param s The buffer into which to read the line
    41a6c3
      * @param n The size of the buffer
    41a6c3
      * @param r The request
    41a6c3
    - * @param fold Whether to merge continuation lines
    41a6c3
    + * @param flags Bit flag of multiple parsing options
    41a6c3
    + *              AP_GETLINE_FOLD Whether to merge continuation lines
    41a6c3
    + *              AP_GETLINE_CRLF Whether line ends must be in the form CR LF
    41a6c3
      * @return The length of the line, if successful
    41a6c3
      *         n, if the line is too big to fit in the buffer
    41a6c3
      *         -1 for miscellaneous errors
    41a6c3
      */
    41a6c3
    -AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int fold);
    41a6c3
    +AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int flags);
    41a6c3
     
    41a6c3
     /**
    41a6c3
      * Get the next line of input for the request
    41a6c3
    @@ -610,7 +615,9 @@
    41a6c3
      * @param n The size of the buffer
    41a6c3
      * @param read The length of the line.
    41a6c3
      * @param r The request
    41a6c3
    - * @param fold Whether to merge continuation lines
    41a6c3
    + * @param flags Bit flag of multiple parsing options
    41a6c3
    + *              AP_GETLINE_FOLD Whether to merge continuation lines
    41a6c3
    + *              AP_GETLINE_CRLF Whether line ends must be in the form CR LF
    41a6c3
      * @param bb Working brigade to use when reading buckets
    41a6c3
      * @return APR_SUCCESS, if successful
    41a6c3
      *         APR_ENOSPC, if the line is too big to fit in the buffer
    41a6c3
    @@ -619,7 +626,7 @@
    41a6c3
     #if APR_CHARSET_EBCDIC
    41a6c3
     AP_DECLARE(apr_status_t) ap_rgetline(char **s, apr_size_t n,
    41a6c3
                                          apr_size_t *read,
    41a6c3
    -                                     request_rec *r, int fold,
    41a6c3
    +                                     request_rec *r, int flags,
    41a6c3
                                          apr_bucket_brigade *bb);
    41a6c3
     #else /* ASCII box */
    41a6c3
     #define ap_rgetline(s, n, read, r, fold, bb) \
    41a6c3
    @@ -629,7 +636,7 @@
    41a6c3
     /** @see ap_rgetline */
    41a6c3
     AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
    41a6c3
                                               apr_size_t *read,
    41a6c3
    -                                          request_rec *r, int fold,
    41a6c3
    +                                          request_rec *r, int flags,
    41a6c3
                                               apr_bucket_brigade *bb);
    41a6c3
     
    41a6c3
     /**
    41a6c3
    diff -uap httpd-2.4.6/modules/http/http_filters.c.cve8743 httpd-2.4.6/modules/http/http_filters.c
    41a6c3
    --- httpd-2.4.6/modules/http/http_filters.c.cve8743
    41a6c3
    +++ httpd-2.4.6/modules/http/http_filters.c
    41a6c3
    @@ -126,14 +126,15 @@
    41a6c3
     
    41a6c3
     /**
    41a6c3
      * Parse a chunk line with optional extension, detect overflow.
    41a6c3
    - * There are two error cases:
    41a6c3
    - *  1) If the conversion would require too many bits, APR_EGENERAL is returned.
    41a6c3
    - *  2) If the conversion used the correct number of bits, but an overflow
    41a6c3
    + * There are several error cases:
    41a6c3
    + *  1) If the chunk link is misformatted, APR_EINVAL is returned.
    41a6c3
    + *  2) If the conversion would require too many bits, APR_EGENERAL is returned.
    41a6c3
    + *  3) If the conversion used the correct number of bits, but an overflow
    41a6c3
      *     caused only the sign bit to flip, then APR_ENOSPC is returned.
    41a6c3
    - * In general, any negative number can be considered an overflow error.
    41a6c3
    + * A negative chunk length always indicates an overflow error.
    41a6c3
      */
    41a6c3
     static apr_status_t parse_chunk_size(http_ctx_t *ctx, const char *buffer,
    41a6c3
    -                                     apr_size_t len, int linelimit)
    41a6c3
    +                                     apr_size_t len, int linelimit, int strict)
    41a6c3
     {
    41a6c3
         apr_size_t i = 0;
    41a6c3
     
    41a6c3
    @@ -146,6 +147,12 @@
    41a6c3
             if (ctx->state == BODY_CHUNK_END
    41a6c3
                     || ctx->state == BODY_CHUNK_END_LF) {
    41a6c3
                 if (c == LF) {
    41a6c3
    +                if (strict && (ctx->state != BODY_CHUNK_END_LF)) {
    41a6c3
    +                    /*
    41a6c3
    +                     * CR missing before LF.
    41a6c3
    +                     */
    41a6c3
    +                    return APR_EINVAL;
    41a6c3
    +                }
    41a6c3
                     ctx->state = BODY_CHUNK;
    41a6c3
                 }
    41a6c3
                 else if (c == CR && ctx->state == BODY_CHUNK_END) {
    41a6c3
    @@ -153,7 +160,7 @@
    41a6c3
                 }
    41a6c3
                 else {
    41a6c3
                     /*
    41a6c3
    -                 * LF expected.
    41a6c3
    +                 * CRLF expected.
    41a6c3
                      */
    41a6c3
                     return APR_EINVAL;
    41a6c3
                 }
    41a6c3
    @@ -180,6 +187,12 @@
    41a6c3
             }
    41a6c3
     
    41a6c3
             if (c == LF) {
    41a6c3
    +            if (strict && (ctx->state != BODY_CHUNK_LF)) {
    41a6c3
    +                /*
    41a6c3
    +                 * CR missing before LF.
    41a6c3
    +                 */
    41a6c3
    +                return APR_EINVAL;
    41a6c3
    +            }
    41a6c3
                 if (ctx->remaining) {
    41a6c3
                     ctx->state = BODY_CHUNK_DATA;
    41a6c3
                 }
    41a6c3
    @@ -201,14 +214,17 @@
    41a6c3
             }
    41a6c3
             else if (ctx->state == BODY_CHUNK_EXT) {
    41a6c3
                 /*
    41a6c3
    -             * Control chars (but tabs) are invalid.
    41a6c3
    +             * Control chars (excluding tabs) are invalid.
    41a6c3
    +             * TODO: more precisely limit input
    41a6c3
                  */
    41a6c3
                 if (c != '\t' && apr_iscntrl(c)) {
    41a6c3
                     return APR_EINVAL;
    41a6c3
                 }
    41a6c3
             }
    41a6c3
             else if (c == ' ' || c == '\t') {
    41a6c3
    -            /* Be lenient up to 10 BWS (term from rfc7230 - 3.2.3).
    41a6c3
    +            /* Be lenient up to 10 implied *LWS, a legacy of RFC 2616,
    41a6c3
    +             * and noted as errata to RFC7230;
    41a6c3
    +             * https://www.rfc-editor.org/errata_search.php?rfc=7230&eid=4667
    41a6c3
                  */
    41a6c3
                 ctx->state = BODY_CHUNK_CR;
    41a6c3
                 if (++ctx->chunk_bws > 10) {
    41a6c3
    @@ -324,7 +340,10 @@
    41a6c3
                                 ap_input_mode_t mode, apr_read_type_e block,
    41a6c3
                                 apr_off_t readbytes)
    41a6c3
     {
    41a6c3
    -    core_server_config *conf;
    41a6c3
    +    core_server_config *conf =
    41a6c3
    +        (core_server_config *) ap_get_module_config(f->r->server->module_config,
    41a6c3
    +                                                    &core_module);
    41a6c3
    +    int strict = (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE);
    41a6c3
         apr_bucket *e;
    41a6c3
         http_ctx_t *ctx = f->ctx;
    41a6c3
         apr_status_t rv;
    41a6c3
    @@ -332,9 +351,6 @@
    41a6c3
         apr_bucket_brigade *bb;
    41a6c3
         int again;
    41a6c3
     
    41a6c3
    -    conf = (core_server_config *)
    41a6c3
    -        ap_get_module_config(f->r->server->module_config, &core_module);
    41a6c3
    -
    41a6c3
         /* just get out of the way of things we don't want. */
    41a6c3
         if (mode != AP_MODE_READBYTES && mode != AP_MODE_GETLINE) {
    41a6c3
             return ap_get_brigade(f->next, b, mode, block, readbytes);
    41a6c3
    @@ -526,7 +542,7 @@
    41a6c3
                         if (rv == APR_SUCCESS) {
    41a6c3
                             parsing = 1;
    41a6c3
                             rv = parse_chunk_size(ctx, buffer, len,
    41a6c3
    -                                f->r->server->limit_req_fieldsize);
    41a6c3
    +                                f->r->server->limit_req_fieldsize, strict);
    41a6c3
                         }
    41a6c3
                         if (rv != APR_SUCCESS) {
    41a6c3
                             ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, f->r, APLOGNO(01590)
    41a6c3
    @@ -668,14 +684,121 @@
    41a6c3
         return APR_SUCCESS;
    41a6c3
     }
    41a6c3
     
    41a6c3
    +struct check_header_ctx {
    41a6c3
    +    request_rec *r;
    41a6c3
    +    int strict;
    41a6c3
    +};
    41a6c3
    +
    41a6c3
    +/* check a single header, to be used with apr_table_do() */
    41a6c3
    +static int check_header(struct check_header_ctx *ctx,
    41a6c3
    +                        const char *name, const char **val)
    41a6c3
    +{
    41a6c3
    +    const char *pos, *end;
    41a6c3
    +    char *dst = NULL;
    41a6c3
    +
    41a6c3
    +    if (name[0] == '\0') {
    41a6c3
    +        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, ctx->r, APLOGNO(02428)
    41a6c3
    +                      "Empty response header name, aborting request");
    41a6c3
    +        return 0;
    41a6c3
    +    }
    41a6c3
    +
    41a6c3
    +    if (ctx->strict) {
    41a6c3
    +        end = ap_scan_http_token(name);
    41a6c3
    +    }
    41a6c3
    +    else {
    41a6c3
    +        end = ap_scan_vchar_obstext(name);
    41a6c3
    +    }
    41a6c3
    +    if (*end) {
    41a6c3
    +        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, ctx->r, APLOGNO(02429)
    41a6c3
    +                      "Response header name '%s' contains invalid "
    41a6c3
    +                      "characters, aborting request",
    41a6c3
    +                      name);
    41a6c3
    +        return 0;
    41a6c3
    +    }
    41a6c3
    +
    41a6c3
    +    for (pos = *val; *pos; pos = end) {
    41a6c3
    +        end = ap_scan_http_field_content(pos);
    41a6c3
    +        if (*end) {
    41a6c3
    +            if (end[0] != CR || end[1] != LF || (end[2] != ' ' &&
    41a6c3
    +                                                 end[2] != '\t')) {
    41a6c3
    +                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, ctx->r, APLOGNO(02430)
    41a6c3
    +                              "Response header '%s' value of '%s' contains "
    41a6c3
    +                              "invalid characters, aborting request",
    41a6c3
    +                              name, pos);
    41a6c3
    +                return 0;
    41a6c3
    +            }
    41a6c3
    +            if (!dst) {
    41a6c3
    +                *val = dst = apr_palloc(ctx->r->pool, strlen(*val) + 1);
    41a6c3
    +            }
    41a6c3
    +        }
    41a6c3
    +        if (dst) {
    41a6c3
    +            memcpy(dst, pos, end - pos);
    41a6c3
    +            dst += end - pos;
    41a6c3
    +            if (*end) {
    41a6c3
    +                /* skip folding and replace with a single space */
    41a6c3
    +                end += 3 + strspn(end + 3, "\t ");
    41a6c3
    +                *dst++ = ' ';
    41a6c3
    +            }
    41a6c3
    +        }
    41a6c3
    +    }
    41a6c3
    +    if (dst) {
    41a6c3
    +        *dst = '\0';
    41a6c3
    +    }
    41a6c3
    +    return 1;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
    +static int check_headers_table(apr_table_t *t, struct check_header_ctx *ctx)
    41a6c3
    +{
    41a6c3
    +    const apr_array_header_t *headers = apr_table_elts(t);
    41a6c3
    +    apr_table_entry_t *header;
    41a6c3
    +    int i;
    41a6c3
    +
    41a6c3
    +    for (i = 0; i < headers->nelts; ++i) {
    41a6c3
    +        header = &APR_ARRAY_IDX(headers, i, apr_table_entry_t);
    41a6c3
    +        if (!header->key) {
    41a6c3
    +            continue;
    41a6c3
    +        }
    41a6c3
    +        if (!check_header(ctx, header->key, (const char **)&header->val)) {
    41a6c3
    +            return 0;
    41a6c3
    +        }
    41a6c3
    +    }
    41a6c3
    +    return 1;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
    +/**
    41a6c3
    + * Check headers for HTTP conformance
    41a6c3
    + * @return 1 if ok, 0 if bad
    41a6c3
    + */
    41a6c3
    +static APR_INLINE int check_headers(request_rec *r)
    41a6c3
    +{
    41a6c3
    +    struct check_header_ctx ctx;
    41a6c3
    +    core_server_config *conf =
    41a6c3
    +            ap_get_core_module_config(r->server->module_config);
    41a6c3
    +
    41a6c3
    +    ctx.r = r;
    41a6c3
    +    ctx.strict = (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE);
    41a6c3
    +    return check_headers_table(r->headers_out, &ctx) &&
    41a6c3
    +           check_headers_table(r->err_headers_out, &ctx;;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
    +static int check_headers_recursion(request_rec *r)
    41a6c3
    +{
    41a6c3
    +    void *check = NULL;
    41a6c3
    +    apr_pool_userdata_get(&check, "check_headers_recursion", r->pool);
    41a6c3
    +    if (check) {
    41a6c3
    +        return 1;
    41a6c3
    +    }
    41a6c3
    +    apr_pool_userdata_setn("true", "check_headers_recursion", NULL, r->pool);
    41a6c3
    +    return 0;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
     typedef struct header_struct {
    41a6c3
         apr_pool_t *pool;
    41a6c3
         apr_bucket_brigade *bb;
    41a6c3
     } header_struct;
    41a6c3
     
    41a6c3
     /* Send a single HTTP header field to the client.  Note that this function
    41a6c3
    - * is used in calls to table_do(), so their interfaces are co-dependent.
    41a6c3
    - * In other words, don't change this one without checking table_do in alloc.c.
    41a6c3
    + * is used in calls to apr_table_do(), so don't change its interface.
    41a6c3
      * It returns true unless there was a write error of some kind.
    41a6c3
      */
    41a6c3
     static int form_header_field(header_struct *h,
    41a6c3
    @@ -1160,6 +1283,7 @@
    41a6c3
     
    41a6c3
     typedef struct header_filter_ctx {
    41a6c3
         int headers_sent;
    41a6c3
    +    int headers_error;
    41a6c3
     } header_filter_ctx;
    41a6c3
     
    41a6c3
     AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f,
    41a6c3
    @@ -1175,19 +1299,23 @@
    41a6c3
         header_filter_ctx *ctx = f->ctx;
    41a6c3
         const char *ctype;
    41a6c3
         ap_bucket_error *eb = NULL;
    41a6c3
    +    apr_bucket *eos = NULL;
    41a6c3
     
    41a6c3
         AP_DEBUG_ASSERT(!r->main);
    41a6c3
     
    41a6c3
    -    if (r->header_only) {
    41a6c3
    -        if (!ctx) {
    41a6c3
    -            ctx = f->ctx = apr_pcalloc(r->pool, sizeof(header_filter_ctx));
    41a6c3
    -        }
    41a6c3
    -        else if (ctx->headers_sent) {
    41a6c3
    +    if (!ctx) {
    41a6c3
    +        ctx = f->ctx = apr_pcalloc(r->pool, sizeof(header_filter_ctx));
    41a6c3
    +    }
    41a6c3
    +    if (ctx->headers_sent) {
    41a6c3
    +        /* Eat body if response must not have one. */
    41a6c3
    +        if (r->header_only || r->status == HTTP_NO_CONTENT) {
    41a6c3
                 apr_brigade_cleanup(b);
    41a6c3
    -            return OK;
    41a6c3
    +            return APR_SUCCESS;
    41a6c3
             }
    41a6c3
         }
    41a6c3
    -
    41a6c3
    +    else if (!ctx->headers_error && !check_headers(r)) {
    41a6c3
    +        ctx->headers_error = 1;
    41a6c3
    +    }
    41a6c3
         for (e = APR_BRIGADE_FIRST(b);
    41a6c3
              e != APR_BRIGADE_SENTINEL(b);
    41a6c3
              e = APR_BUCKET_NEXT(e))
    41a6c3
    @@ -1204,10 +1332,44 @@
    41a6c3
                 ap_remove_output_filter(f);
    41a6c3
                 return ap_pass_brigade(f->next, b);
    41a6c3
             }
    41a6c3
    +        if (ctx->headers_error && APR_BUCKET_IS_EOS(e)) {
    41a6c3
    +            eos = e;
    41a6c3
    +        }
    41a6c3
         }
    41a6c3
    -    if (eb) {
    41a6c3
    -        int status;
    41a6c3
    +    if (ctx->headers_error) {
    41a6c3
    +        if (!eos) {
    41a6c3
    +            /* Eat body until EOS */
    41a6c3
    +            apr_brigade_cleanup(b);
    41a6c3
    +            return APR_SUCCESS;
    41a6c3
    +        }
    41a6c3
     
    41a6c3
    +        /* We may come back here from ap_die() below,
    41a6c3
    +         * so clear anything from this response.
    41a6c3
    +         */
    41a6c3
    +        ctx->headers_error = 0;
    41a6c3
    +        apr_table_clear(r->headers_out);
    41a6c3
    +        apr_table_clear(r->err_headers_out);
    41a6c3
    +
    41a6c3
    +        /* Don't recall ap_die() if we come back here (from its own internal
    41a6c3
    +         * redirect or error response), otherwise we can end up in infinite
    41a6c3
    +         * recursion; better fall through with 500, minimal headers and an
    41a6c3
    +         * empty body (EOS only).
    41a6c3
    +         */
    41a6c3
    +        if (!check_headers_recursion(r)) {
    41a6c3
    +            apr_brigade_cleanup(b);
    41a6c3
    +            ap_die(HTTP_INTERNAL_SERVER_ERROR, r);
    41a6c3
    +            return AP_FILTER_ERROR;
    41a6c3
    +        }
    41a6c3
    +        APR_BUCKET_REMOVE(eos);
    41a6c3
    +        apr_brigade_cleanup(b);
    41a6c3
    +        APR_BRIGADE_INSERT_TAIL(b, eos);
    41a6c3
    +        r->status = HTTP_INTERNAL_SERVER_ERROR;
    41a6c3
    +        r->content_type = r->content_encoding = NULL;
    41a6c3
    +        r->content_languages = NULL;
    41a6c3
    +        ap_set_content_length(r, 0);
    41a6c3
    +    }
    41a6c3
    +    else if (eb) {
    41a6c3
    +        int status;
    41a6c3
             status = eb->status;
    41a6c3
             apr_brigade_cleanup(b);
    41a6c3
             ap_die(status, r);
    41a6c3
    @@ -1264,6 +1426,10 @@
    41a6c3
             apr_table_unset(r->headers_out, "Content-Length");
    41a6c3
         }
    41a6c3
     
    41a6c3
    +    if (r->status == HTTP_NO_CONTENT) {
    41a6c3
    +        apr_table_unset(r->headers_out, "Content-Length");
    41a6c3
    +    }
    41a6c3
    +
    41a6c3
         ctype = ap_make_content_type(r, r->content_type);
    41a6c3
         if (ctype) {
    41a6c3
             apr_table_setn(r->headers_out, "Content-Type", ctype);
    41a6c3
    @@ -1352,11 +1518,11 @@
    41a6c3
         terminate_header(b2);
    41a6c3
     
    41a6c3
         ap_pass_brigade(f->next, b2);
    41a6c3
    +    ctx->headers_sent = 1;
    41a6c3
     
    41a6c3
    -    if (r->header_only) {
    41a6c3
    +    if (r->header_only || r->status == HTTP_NO_CONTENT) {
    41a6c3
             apr_brigade_cleanup(b);
    41a6c3
    -        ctx->headers_sent = 1;
    41a6c3
    -        return OK;
    41a6c3
    +        return APR_SUCCESS;
    41a6c3
         }
    41a6c3
     
    41a6c3
         r->sent_bodyct = 1;         /* Whatever follows is real body stuff... */
    41a6c3
    diff -uap httpd-2.4.6/server/core.c.cve8743 httpd-2.4.6/server/core.c
    41a6c3
    --- httpd-2.4.6/server/core.c.cve8743
    41a6c3
    +++ httpd-2.4.6/server/core.c
    41a6c3
    @@ -506,6 +506,15 @@
    41a6c3
         if (virt->trace_enable != AP_TRACE_UNSET)
    41a6c3
             conf->trace_enable = virt->trace_enable;
    41a6c3
     
    41a6c3
    +    if (virt->http09_enable != AP_HTTP09_UNSET)
    41a6c3
    +        conf->http09_enable = virt->http09_enable;
    41a6c3
    +
    41a6c3
    +    if (virt->http_conformance != AP_HTTP_CONFORMANCE_UNSET)
    41a6c3
    +        conf->http_conformance = virt->http_conformance;
    41a6c3
    +
    41a6c3
    +    if (virt->http_methods != AP_HTTP_METHODS_UNSET)
    41a6c3
    +        conf->http_methods = virt->http_methods;
    41a6c3
    +
    41a6c3
         /* no action for virt->accf_map, not allowed per-vhost */
    41a6c3
     
    41a6c3
         if (virt->protocol)
    41a6c3
    @@ -3632,6 +3641,57 @@
    41a6c3
         return NULL;
    41a6c3
     }
    41a6c3
     
    41a6c3
    +static const char *set_http_protocol_options(cmd_parms *cmd, void *dummy,
    41a6c3
    +                                             const char *arg)
    41a6c3
    +{
    41a6c3
    +    core_server_config *conf =
    41a6c3
    +        ap_get_core_module_config(cmd->server->module_config);
    41a6c3
    +
    41a6c3
    +    if (strcasecmp(arg, "allow0.9") == 0)
    41a6c3
    +        conf->http09_enable |= AP_HTTP09_ENABLE;
    41a6c3
    +    else if (strcasecmp(arg, "require1.0") == 0)
    41a6c3
    +        conf->http09_enable |= AP_HTTP09_DISABLE;
    41a6c3
    +    else if (strcasecmp(arg, "strict") == 0)
    41a6c3
    +        conf->http_conformance |= AP_HTTP_CONFORMANCE_STRICT;
    41a6c3
    +    else if (strcasecmp(arg, "unsafe") == 0)
    41a6c3
    +        conf->http_conformance |= AP_HTTP_CONFORMANCE_UNSAFE;
    41a6c3
    +    else if (strcasecmp(arg, "registeredmethods") == 0)
    41a6c3
    +        conf->http_methods |= AP_HTTP_METHODS_REGISTERED;
    41a6c3
    +    else if (strcasecmp(arg, "lenientmethods") == 0)
    41a6c3
    +        conf->http_methods |= AP_HTTP_METHODS_LENIENT;
    41a6c3
    +    else
    41a6c3
    +        return "HttpProtocolOptions accepts "
    41a6c3
    +               "'Unsafe' or 'Strict' (default), "
    41a6c3
    +               "'RegisteredMethods' or 'LenientMethods' (default), and "
    41a6c3
    +               "'Require1.0' or 'Allow0.9' (default)";
    41a6c3
    +
    41a6c3
    +    if ((conf->http09_enable & AP_HTTP09_ENABLE)
    41a6c3
    +            && (conf->http09_enable & AP_HTTP09_DISABLE))
    41a6c3
    +        return "HttpProtocolOptions 'Allow0.9' and 'Require1.0'"
    41a6c3
    +               " are mutually exclusive";
    41a6c3
    +
    41a6c3
    +    if ((conf->http_conformance & AP_HTTP_CONFORMANCE_STRICT)
    41a6c3
    +            && (conf->http_conformance & AP_HTTP_CONFORMANCE_UNSAFE))
    41a6c3
    +        return "HttpProtocolOptions 'Strict' and 'Unsafe'"
    41a6c3
    +               " are mutually exclusive";
    41a6c3
    +
    41a6c3
    +    if ((conf->http_methods & AP_HTTP_METHODS_REGISTERED)
    41a6c3
    +            && (conf->http_methods & AP_HTTP_METHODS_LENIENT))
    41a6c3
    +        return "HttpProtocolOptions 'RegisteredMethods' and 'LenientMethods'"
    41a6c3
    +               " are mutually exclusive";
    41a6c3
    +
    41a6c3
    +    return NULL;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
    +static const char *set_http_method(cmd_parms *cmd, void *conf, const char *arg)
    41a6c3
    +{
    41a6c3
    +    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
    41a6c3
    +    if (err != NULL)
    41a6c3
    +        return err;
    41a6c3
    +    ap_method_register(cmd->pool, arg);
    41a6c3
    +    return NULL;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
     static apr_hash_t *errorlog_hash;
    41a6c3
     
    41a6c3
     static int log_constant_item(const ap_errorlog_info *info, const char *arg,
    41a6c3
    @@ -4143,6 +4203,13 @@
    41a6c3
                   "'on' (default), 'off' or 'extended' to trace request body content"),
    41a6c3
     AP_INIT_FLAG("MergeTrailers", set_merge_trailers, NULL, RSRC_CONF,
    41a6c3
                   "merge request trailers into request headers or not"),
    41a6c3
    +AP_INIT_ITERATE("HttpProtocolOptions", set_http_protocol_options, NULL, RSRC_CONF,
    41a6c3
    +                "'Allow0.9' or 'Require1.0' (default); "
    41a6c3
    +                "'RegisteredMethods' or 'LenientMethods' (default); "
    41a6c3
    +                "'Unsafe' or 'Strict' (default). Sets HTTP acceptance rules")
    41a6c3
    +,
    41a6c3
    +AP_INIT_ITERATE("RegisterHttpMethod", set_http_method, NULL, RSRC_CONF,
    41a6c3
    +                "Registers non-standard HTTP methods"),
    41a6c3
     { NULL }
    41a6c3
     };
    41a6c3
     
    41a6c3
    diff -uap httpd-2.4.6/server/gen_test_char.c.cve8743 httpd-2.4.6/server/gen_test_char.c
    41a6c3
    --- httpd-2.4.6/server/gen_test_char.c.cve8743
    41a6c3
    +++ httpd-2.4.6/server/gen_test_char.c
    41a6c3
    @@ -16,11 +16,11 @@
    41a6c3
     
    41a6c3
     #ifdef CROSS_COMPILE
    41a6c3
     
    41a6c3
    +#include <ctype.h>
    41a6c3
     #define apr_isalnum(c) (isalnum(((unsigned char)(c))))
    41a6c3
     #define apr_isalpha(c) (isalpha(((unsigned char)(c))))
    41a6c3
     #define apr_iscntrl(c) (iscntrl(((unsigned char)(c))))
    41a6c3
     #define apr_isprint(c) (isprint(((unsigned char)(c))))
    41a6c3
    -#include <ctype.h>
    41a6c3
     #define APR_HAVE_STDIO_H 1
    41a6c3
     #define APR_HAVE_STRING_H 1
    41a6c3
     
    41a6c3
    @@ -52,11 +52,13 @@
    41a6c3
     #define T_ESCAPE_LOGITEM      (0x10)
    41a6c3
     #define T_ESCAPE_FORENSIC     (0x20)
    41a6c3
     #define T_ESCAPE_URLENCODED   (0x40)
    41a6c3
    +#define T_HTTP_CTRLS          (0x80)
    41a6c3
    +#define T_VCHAR_OBSTEXT      (0x100)
    41a6c3
     
    41a6c3
     int main(int argc, char *argv[])
    41a6c3
     {
    41a6c3
         unsigned c;
    41a6c3
    -    unsigned char flags;
    41a6c3
    +    unsigned short flags;
    41a6c3
     
    41a6c3
         printf("/* this file is automatically generated by gen_test_char, "
    41a6c3
                "do not edit */\n"
    41a6c3
    @@ -67,19 +69,23 @@
    41a6c3
                "#define T_ESCAPE_LOGITEM       (%u)\n"
    41a6c3
                "#define T_ESCAPE_FORENSIC      (%u)\n"
    41a6c3
                "#define T_ESCAPE_URLENCODED    (%u)\n"
    41a6c3
    +           "#define T_HTTP_CTRLS           (%u)\n"
    41a6c3
    +           "#define T_VCHAR_OBSTEXT        (%u)\n"
    41a6c3
                "\n"
    41a6c3
    -           "static const unsigned char test_char_table[256] = {",
    41a6c3
    +           "static const unsigned short test_char_table[256] = {",
    41a6c3
                T_ESCAPE_SHELL_CMD,
    41a6c3
                T_ESCAPE_PATH_SEGMENT,
    41a6c3
                T_OS_ESCAPE_PATH,
    41a6c3
                T_HTTP_TOKEN_STOP,
    41a6c3
                T_ESCAPE_LOGITEM,
    41a6c3
                T_ESCAPE_FORENSIC,
    41a6c3
    -           T_ESCAPE_URLENCODED);
    41a6c3
    +           T_ESCAPE_URLENCODED,
    41a6c3
    +           T_HTTP_CTRLS,
    41a6c3
    +           T_VCHAR_OBSTEXT);
    41a6c3
     
    41a6c3
         for (c = 0; c < 256; ++c) {
    41a6c3
             flags = 0;
    41a6c3
    -        if (c % 20 == 0)
    41a6c3
    +        if (c % 8 == 0)
    41a6c3
                 printf("\n    ");
    41a6c3
     
    41a6c3
             /* escape_shell_cmd */
    41a6c3
    @@ -107,7 +113,7 @@
    41a6c3
                 flags |= T_ESCAPE_PATH_SEGMENT;
    41a6c3
             }
    41a6c3
     
    41a6c3
    -        if (!apr_isalnum(c) && !strchr("$-_.+!*'(),:@&=/~", c)) {
    41a6c3
    +        if (!apr_isalnum(c) && !strchr("$-_.+!*'(),:;@&=/~", c)) {
    41a6c3
                 flags |= T_OS_ESCAPE_PATH;
    41a6c3
             }
    41a6c3
     
    41a6c3
    @@ -115,11 +121,32 @@
    41a6c3
                 flags |= T_ESCAPE_URLENCODED;
    41a6c3
             }
    41a6c3
     
    41a6c3
    -        /* these are the "tspecials" (RFC2068) or "separators" (RFC2616) */
    41a6c3
    -        if (c && (apr_iscntrl(c) || strchr(" \t()<>@,;:\\\"/[]?={}", c))) {
    41a6c3
    +        /* Stop for any non-'token' character, including ctrls, obs-text,
    41a6c3
    +         * and "tspecials" (RFC2068) a.k.a. "separators" (RFC2616), which
    41a6c3
    +         * is easer to express as characters remaining in the ASCII token set
    41a6c3
    +         */
    41a6c3
    +        if (!c || !(apr_isalnum(c) || strchr("!#$%&'*+-.^_`|~", c))) {
    41a6c3
                 flags |= T_HTTP_TOKEN_STOP;
    41a6c3
             }
    41a6c3
     
    41a6c3
    +        /* Catch CTRLs other than VCHAR, HT and SP, and obs-text (RFC7230 3.2)
    41a6c3
    +         * This includes only the C0 plane, not C1 (which is obs-text itself.)
    41a6c3
    +         * XXX: We should verify that all ASCII C0 ctrls/DEL corresponding to
    41a6c3
    +         * the current EBCDIC translation are captured, and ASCII C1 ctrls
    41a6c3
    +         * corresponding are all permitted (as they fall under obs-text rule)
    41a6c3
    +         */
    41a6c3
    +        if (!c || (apr_iscntrl(c) && c != '\t')) {
    41a6c3
    +            flags |= T_HTTP_CTRLS;
    41a6c3
    +        }
    41a6c3
    +
    41a6c3
    +        /* From RFC3986, the specific sets of gen-delims, sub-delims (2.2),
    41a6c3
    +         * and unreserved (2.3) that are possible somewhere within a URI.
    41a6c3
    +         * Spec requires all others to be %XX encoded, including obs-text.
    41a6c3
    +         */
    41a6c3
    +        if (c && !apr_iscntrl(c) && c != ' ') {
    41a6c3
    +            flags |= T_VCHAR_OBSTEXT;
    41a6c3
    +        }
    41a6c3
    +
    41a6c3
             /* For logging, escape all control characters,
    41a6c3
              * double quotes (because they delimit the request in the log file)
    41a6c3
              * backslashes (because we use backslash for escaping)
    41a6c3
    @@ -137,7 +164,7 @@
    41a6c3
                 flags |= T_ESCAPE_FORENSIC;
    41a6c3
             }
    41a6c3
     
    41a6c3
    -        printf("%u%c", flags, (c < 255) ? ',' : ' ');
    41a6c3
    +        printf("0x%03x%c", flags, (c < 255) ? ',' : ' ');
    41a6c3
         }
    41a6c3
     
    41a6c3
         printf("\n};\n");
    41a6c3
    diff -uap httpd-2.4.6/server/protocol.c.cve8743 httpd-2.4.6/server/protocol.c
    41a6c3
    --- httpd-2.4.6/server/protocol.c.cve8743
    41a6c3
    +++ httpd-2.4.6/server/protocol.c
    41a6c3
    @@ -189,6 +189,10 @@
    41a6c3
      * caused by MIME folding (or broken clients) if fold != 0, and place it
    41a6c3
      * in the buffer s, of size n bytes, without the ending newline.
    41a6c3
      *
    41a6c3
    + * Pulls from r->proto_input_filters instead of r->input_filters for
    41a6c3
    + * stricter protocol adherence and better input filter behavior during
    41a6c3
    + * chunked trailer processing (for http).
    41a6c3
    + *
    41a6c3
      * If s is NULL, ap_rgetline_core will allocate necessary memory from r->pool.
    41a6c3
      *
    41a6c3
      * Returns APR_SUCCESS if there are no problems and sets *read to be
    41a6c3
    @@ -197,7 +201,7 @@
    41a6c3
      * APR_ENOSPC is returned if there is not enough buffer space.
    41a6c3
      * Other errors may be returned on other errors.
    41a6c3
      *
    41a6c3
    - * The LF is *not* returned in the buffer.  Therefore, a *read of 0
    41a6c3
    + * The [CR]LF are *not* returned in the buffer.  Therefore, a *read of 0
    41a6c3
      * indicates that an empty line was read.
    41a6c3
      *
    41a6c3
      * Notes: Because the buffer uses 1 char for NUL, the most we can return is
    41a6c3
    @@ -208,13 +212,15 @@
    41a6c3
      */
    41a6c3
     AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
    41a6c3
                                               apr_size_t *read, request_rec *r,
    41a6c3
    -                                          int fold, apr_bucket_brigade *bb)
    41a6c3
    +                                          int flags, apr_bucket_brigade *bb)
    41a6c3
     {
    41a6c3
         apr_status_t rv;
    41a6c3
         apr_bucket *e;
    41a6c3
         apr_size_t bytes_handled = 0, current_alloc = 0;
    41a6c3
         char *pos, *last_char = *s;
    41a6c3
         int do_alloc = (*s == NULL), saw_eos = 0;
    41a6c3
    +    int fold = flags & AP_GETLINE_FOLD;
    41a6c3
    +    int crlf = flags & AP_GETLINE_CRLF;
    41a6c3
     
    41a6c3
         /*
    41a6c3
          * Initialize last_char as otherwise a random value will be compared
    41a6c3
    @@ -226,13 +232,15 @@
    41a6c3
     
    41a6c3
         for (;;) {
    41a6c3
             apr_brigade_cleanup(bb);
    41a6c3
    -        rv = ap_get_brigade(r->input_filters, bb, AP_MODE_GETLINE,
    41a6c3
    +        rv = ap_get_brigade(r->proto_input_filters, bb, AP_MODE_GETLINE,
    41a6c3
                                 APR_BLOCK_READ, 0);
    41a6c3
             if (rv != APR_SUCCESS) {
    41a6c3
                 return rv;
    41a6c3
             }
    41a6c3
     
    41a6c3
    -        /* Something horribly wrong happened.  Someone didn't block! */
    41a6c3
    +        /* Something horribly wrong happened.  Someone didn't block! 
    41a6c3
    +         * (this also happens at the end of each keepalive connection)
    41a6c3
    +         */
    41a6c3
             if (APR_BRIGADE_EMPTY(bb)) {
    41a6c3
                 return APR_EGENERAL;
    41a6c3
             }
    41a6c3
    @@ -318,6 +326,13 @@
    41a6c3
             }
    41a6c3
         }
    41a6c3
     
    41a6c3
    +    if (crlf && (last_char <= *s || last_char[-1] != APR_ASCII_CR)) {
    41a6c3
    +        *last_char = '\0';
    41a6c3
    +        bytes_handled = last_char - *s;
    41a6c3
    +        *read = bytes_handled;
    41a6c3
    +        return APR_EINVAL;
    41a6c3
    +    }
    41a6c3
    +
    41a6c3
         /* Now NUL-terminate the string at the end of the line;
    41a6c3
          * if the last-but-one character is a CR, terminate there */
    41a6c3
         if (last_char > *s && last_char[-1] == APR_ASCII_CR) {
    41a6c3
    @@ -340,7 +355,7 @@
    41a6c3
                 apr_brigade_cleanup(bb);
    41a6c3
     
    41a6c3
                 /* We only care about the first byte. */
    41a6c3
    -            rv = ap_get_brigade(r->input_filters, bb, AP_MODE_SPECULATIVE,
    41a6c3
    +            rv = ap_get_brigade(r->proto_input_filters, bb, AP_MODE_SPECULATIVE,
    41a6c3
                                     APR_BLOCK_READ, 1);
    41a6c3
                 if (rv != APR_SUCCESS) {
    41a6c3
                     return rv;
    41a6c3
    @@ -391,7 +406,8 @@
    41a6c3
                          */
    41a6c3
                         if (do_alloc) {
    41a6c3
                             tmp = NULL;
    41a6c3
    -                    } else {
    41a6c3
    +                    }
    41a6c3
    +                    else {
    41a6c3
                             /* We're null terminated. */
    41a6c3
                             tmp = last_char;
    41a6c3
                         }
    41a6c3
    @@ -461,7 +477,7 @@
    41a6c3
     }
    41a6c3
     #endif
    41a6c3
     
    41a6c3
    -AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int fold)
    41a6c3
    +AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int flags)
    41a6c3
     {
    41a6c3
         char *tmp_s = s;
    41a6c3
         apr_status_t rv;
    41a6c3
    @@ -469,7 +485,7 @@
    41a6c3
         apr_bucket_brigade *tmp_bb;
    41a6c3
     
    41a6c3
         tmp_bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
    41a6c3
    -    rv = ap_rgetline(&tmp_s, n, &len, r, fold, tmp_bb);
    41a6c3
    +    rv = ap_rgetline(&tmp_s, n, &len, r, flags, tmp_bb);
    41a6c3
         apr_brigade_destroy(tmp_bb);
    41a6c3
     
    41a6c3
         /* Map the out-of-space condition to the old API. */
    41a6c3
    @@ -549,16 +565,29 @@
    41a6c3
         }
    41a6c3
     }
    41a6c3
     
    41a6c3
    -static int read_request_line(request_rec *r, apr_bucket_brigade *bb)
    41a6c3
    +/* get the length of the field name for logging, but no more than 80 bytes */
    41a6c3
    +#define LOG_NAME_MAX_LEN 80
    41a6c3
    +static int field_name_len(const char *field)
    41a6c3
     {
    41a6c3
    -    const char *ll;
    41a6c3
    -    const char *uri;
    41a6c3
    -    const char *pro;
    41a6c3
    +    const char *end = ap_strchr_c(field, ':');
    41a6c3
    +    if (end == NULL || end - field > LOG_NAME_MAX_LEN)
    41a6c3
    +        return LOG_NAME_MAX_LEN;
    41a6c3
    +    return end - field;
    41a6c3
    +}
    41a6c3
     
    41a6c3
    -    int major = 1, minor = 0;   /* Assume HTTP/1.0 if non-"HTTP" protocol */
    41a6c3
    -    char http[5];
    41a6c3
    +static int read_request_line(request_rec *r, apr_bucket_brigade *bb)
    41a6c3
    +{
    41a6c3
    +    enum {
    41a6c3
    +        rrl_none, rrl_badmethod, rrl_badwhitespace, rrl_excesswhitespace,
    41a6c3
    +        rrl_missinguri, rrl_baduri, rrl_badprotocol, rrl_trailingtext,
    41a6c3
    +        rrl_badmethod09, rrl_reject09
    41a6c3
    +    } deferred_error = rrl_none;
    41a6c3
    +    char *ll;
    41a6c3
    +    char *uri;
    41a6c3
         apr_size_t len;
    41a6c3
         int num_blank_lines = 0;
    41a6c3
    +    core_server_config *conf = ap_get_core_module_config(r->server->module_config);
    41a6c3
    +    int strict = (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE);
    41a6c3
         int max_blank_lines = r->server->limit_req_fields;
    41a6c3
     
    41a6c3
         if (max_blank_lines <= 0) {
    41a6c3
    @@ -588,7 +617,7 @@
    41a6c3
              */
    41a6c3
             r->the_request = NULL;
    41a6c3
             rv = ap_rgetline(&(r->the_request), (apr_size_t)(r->server->limit_req_line + 2),
    41a6c3
    -                         &len, r, 0, bb);
    41a6c3
    +                         &len, r, strict ? AP_GETLINE_CRLF : 0, bb);
    41a6c3
     
    41a6c3
             if (rv != APR_SUCCESS) {
    41a6c3
                 r->request_time = apr_time_now();
    41a6c3
    @@ -599,8 +628,6 @@
    41a6c3
                  */
    41a6c3
                 if (APR_STATUS_IS_ENOSPC(rv)) {
    41a6c3
                     r->status    = HTTP_REQUEST_URI_TOO_LARGE;
    41a6c3
    -                r->proto_num = HTTP_VERSION(1,0);
    41a6c3
    -                r->protocol  = apr_pstrdup(r->pool, "HTTP/1.0");
    41a6c3
                 }
    41a6c3
                 else if (APR_STATUS_IS_TIMEUP(rv)) {
    41a6c3
                     r->status = HTTP_REQUEST_TIME_OUT;
    41a6c3
    @@ -608,6 +635,8 @@
    41a6c3
                 else if (APR_STATUS_IS_EINVAL(rv)) {
    41a6c3
                     r->status = HTTP_BAD_REQUEST;
    41a6c3
                 }
    41a6c3
    +            r->proto_num = HTTP_VERSION(1,0);
    41a6c3
    +            r->protocol  = apr_pstrdup(r->pool, "HTTP/1.0");
    41a6c3
                 return 0;
    41a6c3
             }
    41a6c3
         } while ((len <= 0) && (++num_blank_lines < max_blank_lines));
    41a6c3
    @@ -619,46 +648,263 @@
    41a6c3
         }
    41a6c3
     
    41a6c3
         r->request_time = apr_time_now();
    41a6c3
    -    ll = r->the_request;
    41a6c3
    -    r->method = ap_getword_white(r->pool, &ll);
    41a6c3
    +    r->method = r->the_request;
    41a6c3
    +
    41a6c3
    +    /* If there is whitespace before a method, skip it and mark in error */
    41a6c3
    +    if (apr_isspace(*r->method)) {
    41a6c3
    +        deferred_error = rrl_badwhitespace;
    41a6c3
    +        for ( ; apr_isspace(*r->method); ++r->method)
    41a6c3
    +            ;
    41a6c3
    +    }
    41a6c3
     
    41a6c3
    -    uri = ap_getword_white(r->pool, &ll);
    41a6c3
    +    /* Scan the method up to the next whitespace, ensure it contains only
    41a6c3
    +     * valid http-token characters, otherwise mark in error
    41a6c3
    +     */
    41a6c3
    +    if (strict) {
    41a6c3
    +        ll = (char*) ap_scan_http_token(r->method);
    41a6c3
    +    }
    41a6c3
    +    else {
    41a6c3
    +        ll = (char*) ap_scan_vchar_obstext(r->method);
    41a6c3
    +    }
    41a6c3
     
    41a6c3
    -    /* Provide quick information about the request method as soon as known */
    41a6c3
    +    if (((ll == r->method) || (*ll && !apr_isspace(*ll)))
    41a6c3
    +            && deferred_error == rrl_none) {
    41a6c3
    +        deferred_error = rrl_badmethod;
    41a6c3
    +        ll = strpbrk(ll, "\t\n\v\f\r ");
    41a6c3
    +    }
    41a6c3
     
    41a6c3
    -    r->method_number = ap_method_number_of(r->method);
    41a6c3
    -    if (r->method_number == M_GET && r->method[0] == 'H') {
    41a6c3
    -        r->header_only = 1;
    41a6c3
    +    /* Verify method terminated with a single SP, or mark as specific error */
    41a6c3
    +    if (!ll) {
    41a6c3
    +        if (deferred_error == rrl_none)
    41a6c3
    +            deferred_error = rrl_missinguri;
    41a6c3
    +        r->protocol = uri = "";
    41a6c3
    +        len = 0;
    41a6c3
    +        goto rrl_done;
    41a6c3
    +    }
    41a6c3
    +    else if (strict && ll[0] && apr_isspace(ll[1])
    41a6c3
    +             && deferred_error == rrl_none) {
    41a6c3
    +        deferred_error = rrl_excesswhitespace;
    41a6c3
         }
    41a6c3
     
    41a6c3
    -    ap_parse_uri(r, uri);
    41a6c3
    +    /* Advance uri pointer over leading whitespace, NUL terminate the method
    41a6c3
    +     * If non-SP whitespace is encountered, mark as specific error
    41a6c3
    +     */
    41a6c3
    +    for (uri = ll; apr_isspace(*uri); ++uri)
    41a6c3
    +        if (*uri != ' ' && deferred_error == rrl_none)
    41a6c3
    +            deferred_error = rrl_badwhitespace;
    41a6c3
    +    *ll = '\0';
    41a6c3
    +
    41a6c3
    +    if (!*uri && deferred_error == rrl_none)
    41a6c3
    +        deferred_error = rrl_missinguri;
    41a6c3
    +
    41a6c3
    +    /* Scan the URI up to the next whitespace, ensure it contains no raw
    41a6c3
    +     * control characters, otherwise mark in error
    41a6c3
    +     */
    41a6c3
    +    ll = (char*) ap_scan_vchar_obstext(uri);
    41a6c3
    +    if (ll == uri || (*ll && !apr_isspace(*ll))) {
    41a6c3
    +        deferred_error = rrl_baduri;
    41a6c3
    +        ll = strpbrk(ll, "\t\n\v\f\r ");
    41a6c3
    +    }
    41a6c3
     
    41a6c3
    -    if (ll[0]) {
    41a6c3
    +    /* Verify URI terminated with a single SP, or mark as specific error */
    41a6c3
    +    if (!ll) {
    41a6c3
    +        r->protocol = "";
    41a6c3
    +        len = 0;
    41a6c3
    +        goto rrl_done;
    41a6c3
    +    }
    41a6c3
    +    else if (strict && ll[0] && apr_isspace(ll[1])
    41a6c3
    +             && deferred_error == rrl_none) {
    41a6c3
    +        deferred_error = rrl_excesswhitespace;
    41a6c3
    +    }
    41a6c3
    +
    41a6c3
    +    /* Advance protocol pointer over leading whitespace, NUL terminate the uri
    41a6c3
    +     * If non-SP whitespace is encountered, mark as specific error
    41a6c3
    +     */
    41a6c3
    +    for (r->protocol = ll; apr_isspace(*r->protocol); ++r->protocol)
    41a6c3
    +        if (*r->protocol != ' ' && deferred_error == rrl_none)
    41a6c3
    +            deferred_error = rrl_badwhitespace;
    41a6c3
    +    *ll = '\0';
    41a6c3
    +
    41a6c3
    +    /* Scan the protocol up to the next whitespace, validation comes later */
    41a6c3
    +    if (!(ll = (char*) ap_scan_vchar_obstext(r->protocol))) {
    41a6c3
    +        len = strlen(r->protocol);
    41a6c3
    +        goto rrl_done;
    41a6c3
    +    }
    41a6c3
    +    len = ll - r->protocol;
    41a6c3
    +
    41a6c3
    +    /* Advance over trailing whitespace, if found mark in error,
    41a6c3
    +     * determine if trailing text is found, unconditionally mark in error,
    41a6c3
    +     * finally NUL terminate the protocol string
    41a6c3
    +     */
    41a6c3
    +    if (*ll && !apr_isspace(*ll)) {
    41a6c3
    +        deferred_error = rrl_badprotocol;
    41a6c3
    +    }
    41a6c3
    +    else if (strict && *ll) {
    41a6c3
    +        deferred_error = rrl_excesswhitespace;
    41a6c3
    +    }
    41a6c3
    +    else {
    41a6c3
    +        for ( ; apr_isspace(*ll); ++ll)
    41a6c3
    +            if (*ll != ' ' && deferred_error == rrl_none)
    41a6c3
    +                deferred_error = rrl_badwhitespace;
    41a6c3
    +        if (*ll && deferred_error == rrl_none)
    41a6c3
    +            deferred_error = rrl_trailingtext;
    41a6c3
    +    }
    41a6c3
    +    *((char *)r->protocol + len) = '\0';
    41a6c3
    +
    41a6c3
    +rrl_done:
    41a6c3
    +    /* For internal integrety and palloc efficiency, reconstruct the_request
    41a6c3
    +     * in one palloc, using only single SP characters, per spec.
    41a6c3
    +     */
    41a6c3
    +    r->the_request = apr_pstrcat(r->pool, r->method, *uri ? " " : NULL, uri,
    41a6c3
    +                                 *r->protocol ? " " : NULL, r->protocol, NULL);
    41a6c3
    +
    41a6c3
    +    if (len == 8
    41a6c3
    +            && r->protocol[0] == 'H' && r->protocol[1] == 'T'
    41a6c3
    +            && r->protocol[2] == 'T' && r->protocol[3] == 'P'
    41a6c3
    +            && r->protocol[4] == '/' && apr_isdigit(r->protocol[5])
    41a6c3
    +            && r->protocol[6] == '.' && apr_isdigit(r->protocol[7])
    41a6c3
    +            && r->protocol[5] != '0') {
    41a6c3
    +        r->assbackwards = 0;
    41a6c3
    +        r->proto_num = HTTP_VERSION(r->protocol[5] - '0', r->protocol[7] - '0');
    41a6c3
    +    }
    41a6c3
    +    else if (len == 8
    41a6c3
    +                 && (r->protocol[0] == 'H' || r->protocol[0] == 'h')
    41a6c3
    +                 && (r->protocol[1] == 'T' || r->protocol[1] == 't')
    41a6c3
    +                 && (r->protocol[2] == 'T' || r->protocol[2] == 't')
    41a6c3
    +                 && (r->protocol[3] == 'P' || r->protocol[3] == 'p')
    41a6c3
    +                 && r->protocol[4] == '/' && apr_isdigit(r->protocol[5])
    41a6c3
    +                 && r->protocol[6] == '.' && apr_isdigit(r->protocol[7])
    41a6c3
    +                 && r->protocol[5] != '0') {
    41a6c3
             r->assbackwards = 0;
    41a6c3
    -        pro = ll;
    41a6c3
    -        len = strlen(ll);
    41a6c3
    -    } else {
    41a6c3
    +        r->proto_num = HTTP_VERSION(r->protocol[5] - '0', r->protocol[7] - '0');
    41a6c3
    +        if (strict && deferred_error == rrl_none)
    41a6c3
    +            deferred_error = rrl_badprotocol;
    41a6c3
    +        else
    41a6c3
    +            memcpy((char*)r->protocol, "HTTP", 4);
    41a6c3
    +    } else if (r->protocol[0]) {
    41a6c3
    +        r->proto_num = HTTP_VERSION(0, 9);
    41a6c3
    +        /* Defer setting the r->protocol string till error msg is composed */
    41a6c3
    +        if (deferred_error == rrl_none)
    41a6c3
    +            deferred_error = rrl_badprotocol;
    41a6c3
    +    }
    41a6c3
    +    else {
    41a6c3
             r->assbackwards = 1;
    41a6c3
    -        pro = "HTTP/0.9";
    41a6c3
    -        len = 8;
    41a6c3
    +        r->protocol  = apr_pstrdup(r->pool, "HTTP/0.9");
    41a6c3
    +        r->proto_num = HTTP_VERSION(0, 9);
    41a6c3
         }
    41a6c3
    -    r->protocol = apr_pstrmemdup(r->pool, pro, len);
    41a6c3
     
    41a6c3
    -    /* Avoid sscanf in the common case */
    41a6c3
    -    if (len == 8
    41a6c3
    -        && pro[0] == 'H' && pro[1] == 'T' && pro[2] == 'T' && pro[3] == 'P'
    41a6c3
    -        && pro[4] == '/' && apr_isdigit(pro[5]) && pro[6] == '.'
    41a6c3
    -        && apr_isdigit(pro[7])) {
    41a6c3
    -        r->proto_num = HTTP_VERSION(pro[5] - '0', pro[7] - '0');
    41a6c3
    -    }
    41a6c3
    -    else if (3 == sscanf(r->protocol, "%4s/%u.%u", http, &major, &minor)
    41a6c3
    -             && (strcasecmp("http", http) == 0)
    41a6c3
    -             && (minor < HTTP_VERSION(1, 0)) ) /* don't allow HTTP/0.1000 */
    41a6c3
    -        r->proto_num = HTTP_VERSION(major, minor);
    41a6c3
    -    else
    41a6c3
    -        r->proto_num = HTTP_VERSION(1, 0);
    41a6c3
    +    /* Determine the method_number and parse the uri prior to invoking error
    41a6c3
    +     * handling, such that these fields are available for subsitution
    41a6c3
    +     */
    41a6c3
    +    r->method_number = ap_method_number_of(r->method);
    41a6c3
    +    if (r->method_number == M_GET && r->method[0] == 'H')
    41a6c3
    +        r->header_only = 1;
    41a6c3
    +
    41a6c3
    +    ap_parse_uri(r, uri);
    41a6c3
    +
    41a6c3
    +    /* With the request understood, we can consider HTTP/0.9 specific errors */
    41a6c3
    +    if (r->proto_num == HTTP_VERSION(0, 9) && deferred_error == rrl_none) {
    41a6c3
    +        if (conf->http09_enable == AP_HTTP09_DISABLE)
    41a6c3
    +            deferred_error = rrl_reject09;
    41a6c3
    +        else if (strict && (r->method_number != M_GET || r->header_only))
    41a6c3
    +            deferred_error = rrl_badmethod09;
    41a6c3
    +    }
    41a6c3
    +
    41a6c3
    +    /* Now that the method, uri and protocol are all processed,
    41a6c3
    +     * we can safely resume any deferred error reporting
    41a6c3
    +     */
    41a6c3
    +    if (deferred_error != rrl_none) {
    41a6c3
    +        if (deferred_error == rrl_badmethod)
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03445)
    41a6c3
    +                          "HTTP Request Line; Invalid method token: '%.*s'",
    41a6c3
    +                          field_name_len(r->method), r->method);
    41a6c3
    +        else if (deferred_error == rrl_badmethod09)
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03444)
    41a6c3
    +                          "HTTP Request Line; Invalid method token: '%.*s'"
    41a6c3
    +                          " (only GET is allowed for HTTP/0.9 requests)",
    41a6c3
    +                          field_name_len(r->method), r->method);
    41a6c3
    +        else if (deferred_error == rrl_missinguri)
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03446)
    41a6c3
    +                          "HTTP Request Line; Missing URI");
    41a6c3
    +        else if (deferred_error == rrl_baduri)
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03454)
    41a6c3
    +                          "HTTP Request Line; URI incorrectly encoded: '%.*s'",
    41a6c3
    +                          field_name_len(r->uri), r->uri);
    41a6c3
    +        else if (deferred_error == rrl_badwhitespace)
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03447)
    41a6c3
    +                          "HTTP Request Line; Invalid whitespace");
    41a6c3
    +        else if (deferred_error == rrl_excesswhitespace)
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03448)
    41a6c3
    +                          "HTTP Request Line; Excess whitespace "
    41a6c3
    +                          "(disallowed by HttpProtocolOptions Strict");
    41a6c3
    +        else if (deferred_error == rrl_trailingtext)
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03449)
    41a6c3
    +                          "HTTP Request Line; Extraneous text found '%.*s' "
    41a6c3
    +                          "(perhaps whitespace was injected?)",
    41a6c3
    +                          field_name_len(ll), ll);
    41a6c3
    +        else if (deferred_error == rrl_reject09)
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02401)
    41a6c3
    +                          "HTTP Request Line; Rejected HTTP/0.9 request");
    41a6c3
    +        else if (deferred_error == rrl_badprotocol)
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02418)
    41a6c3
    +                          "HTTP Request Line; Unrecognized protocol '%.*s' "
    41a6c3
    +                          "(perhaps whitespace was injected?)",
    41a6c3
    +                          field_name_len(r->protocol), r->protocol);
    41a6c3
    +        r->status = HTTP_BAD_REQUEST;
    41a6c3
    +        goto rrl_failed;
    41a6c3
    +    }
    41a6c3
    +
    41a6c3
    +    if (conf->http_methods == AP_HTTP_METHODS_REGISTERED
    41a6c3
    +            && r->method_number == M_INVALID) {
    41a6c3
    +        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02423)
    41a6c3
    +                      "HTTP Request Line; Unrecognized HTTP method: '%.*s' "
    41a6c3
    +                      "(disallowed by RegisteredMethods)",
    41a6c3
    +                      field_name_len(r->method), r->method);
    41a6c3
    +        r->status = HTTP_NOT_IMPLEMENTED;
    41a6c3
    +        /* This can't happen in an HTTP/0.9 request, we verified GET above */
    41a6c3
    +        return 0;
    41a6c3
    +    }
    41a6c3
    +
    41a6c3
    +    if (r->status != HTTP_OK) {
    41a6c3
    +        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03450)
    41a6c3
    +                      "HTTP Request Line; Unable to parse URI: '%.*s'",
    41a6c3
    +                      field_name_len(r->uri), r->uri);
    41a6c3
    +        goto rrl_failed;
    41a6c3
    +    }
    41a6c3
    +
    41a6c3
    +    if (strict) {
    41a6c3
    +        if (r->parsed_uri.fragment) {
    41a6c3
    +            /* RFC3986 3.5: no fragment */
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02421)
    41a6c3
    +                          "HTTP Request Line; URI must not contain a fragment");
    41a6c3
    +            r->status = HTTP_BAD_REQUEST;
    41a6c3
    +            goto rrl_failed;
    41a6c3
    +        }
    41a6c3
    +        if (r->parsed_uri.user || r->parsed_uri.password) {
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02422)
    41a6c3
    +                          "HTTP Request Line; URI must not contain a "
    41a6c3
    +                          "username/password");
    41a6c3
    +            r->status = HTTP_BAD_REQUEST;
    41a6c3
    +            goto rrl_failed;
    41a6c3
    +        }
    41a6c3
    +    }
    41a6c3
     
    41a6c3
         return 1;
    41a6c3
    +rrl_failed:
    41a6c3
    +    if (r->proto_num == HTTP_VERSION(0, 9)) {
    41a6c3
    +        /* Send all parsing and protocol error response with 1.x behavior,
    41a6c3
    +         * and reserve 505 errors for actual HTTP protocols presented.
    41a6c3
    +         * As called out in RFC7230 3.5, any errors parsing the protocol
    41a6c3
    +         * from the request line are nearly always misencoded HTTP/1.x
    41a6c3
    +         * requests. Only a valid 0.9 request with no parsing errors
    41a6c3
    +         * at all may be treated as a simple request, if allowed.
    41a6c3
    +         */
    41a6c3
    +        r->assbackwards = 0;
    41a6c3
    +        r->connection->keepalive = AP_CONN_CLOSE;
    41a6c3
    +        r->proto_num = HTTP_VERSION(1, 0);
    41a6c3
    +        r->protocol  = apr_pstrdup(r->pool, "HTTP/1.0");
    41a6c3
    +    }
    41a6c3
    +    return 0;
    41a6c3
     }
    41a6c3
     
    41a6c3
     static int table_do_fn_check_lengths(void *r_, const char *key,
    41a6c3
    @@ -670,26 +916,13 @@
    41a6c3
     
    41a6c3
         r->status = HTTP_BAD_REQUEST;
    41a6c3
         apr_table_setn(r->notes, "error-notes",
    41a6c3
    -                   apr_pstrcat(r->pool, "Size of a request header field "
    41a6c3
    -                               "after merging exceeds server limit.
    "
    41a6c3
    -                               "\n
    \n",
    41a6c3
    -                               ap_escape_html(r->pool, key),
    41a6c3
    -                               "\n", NULL));
    41a6c3
    -    ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00560) "Request header "
    41a6c3
    -                  "exceeds LimitRequestFieldSize after merging: %s", key);
    41a6c3
    +                   "Size of a request header field exceeds server limit.");
    41a6c3
    +    ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00560) "Request "
    41a6c3
    +                  "header exceeds LimitRequestFieldSize after merging: %.*s",
    41a6c3
    +                  field_name_len(key), key);
    41a6c3
         return 0;
    41a6c3
     }
    41a6c3
     
    41a6c3
    -/* get the length of the field name for logging, but no more than 80 bytes */
    41a6c3
    -#define LOG_NAME_MAX_LEN 80
    41a6c3
    -static int field_name_len(const char *field)
    41a6c3
    -{
    41a6c3
    -    const char *end = ap_strchr_c(field, ':');
    41a6c3
    -    if (end == NULL || end - field > LOG_NAME_MAX_LEN)
    41a6c3
    -        return LOG_NAME_MAX_LEN;
    41a6c3
    -    return end - field;
    41a6c3
    -}
    41a6c3
    -
    41a6c3
     AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r, apr_bucket_brigade *bb)
    41a6c3
     {
    41a6c3
         char *last_field = NULL;
    41a6c3
    @@ -700,6 +933,8 @@
    41a6c3
         apr_size_t len;
    41a6c3
         int fields_read = 0;
    41a6c3
         char *tmp_field;
    41a6c3
    +    core_server_config *conf = ap_get_core_module_config(r->server->module_config);
    41a6c3
    +    int strict = (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE);
    41a6c3
     
    41a6c3
         /*
    41a6c3
          * Read header lines until we get the empty separator line, a read error,
    41a6c3
    @@ -707,11 +942,10 @@
    41a6c3
          */
    41a6c3
         while(1) {
    41a6c3
             apr_status_t rv;
    41a6c3
    -        int folded = 0;
    41a6c3
     
    41a6c3
             field = NULL;
    41a6c3
             rv = ap_rgetline(&field, r->server->limit_req_fieldsize + 2,
    41a6c3
    -                         &len, r, 0, bb);
    41a6c3
    +                         &len, r, strict ? AP_GETLINE_CRLF : 0, bb);
    41a6c3
     
    41a6c3
             if (rv != APR_SUCCESS) {
    41a6c3
                 if (APR_STATUS_IS_TIMEUP(rv)) {
    41a6c3
    @@ -728,153 +962,217 @@
    41a6c3
                  * exceeds the configured limit for a field size.
    41a6c3
                  */
    41a6c3
                 if (rv == APR_ENOSPC) {
    41a6c3
    -                const char *field_escaped;
    41a6c3
    -                if (field) {
    41a6c3
    -                    /* ensure ap_escape_html will terminate correctly */
    41a6c3
    -                    field[len - 1] = '\0';
    41a6c3
    -                    field_escaped = ap_escape_html(r->pool, field);
    41a6c3
    -                }
    41a6c3
    -                else {
    41a6c3
    -                    field_escaped = field = "";
    41a6c3
    -                }
    41a6c3
    -
    41a6c3
                     apr_table_setn(r->notes, "error-notes",
    41a6c3
    -                               apr_psprintf(r->pool,
    41a6c3
    -                                           "Size of a request header field "
    41a6c3
    -                                           "exceeds server limit.
    \n"
    41a6c3
    -                                           "
    \n%.*s\n
    \n",
    41a6c3
    -                                           field_name_len(field_escaped),
    41a6c3
    -                                           field_escaped));
    41a6c3
    +                               "Size of a request header field "
    41a6c3
    +                               "exceeds server limit.");
    41a6c3
                     ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00561)
    41a6c3
                                   "Request header exceeds LimitRequestFieldSize%s"
    41a6c3
                                   "%.*s",
    41a6c3
    -                              *field ? ": " : "",
    41a6c3
    -                              field_name_len(field), field);
    41a6c3
    +                              (field && *field) ? ": " : "",
    41a6c3
    +                              (field) ? field_name_len(field) : 0,
    41a6c3
    +                              (field) ? field : "");
    41a6c3
                 }
    41a6c3
                 return;
    41a6c3
             }
    41a6c3
     
    41a6c3
    -        if (last_field != NULL) {
    41a6c3
    -            if ((len > 0) && ((*field == '\t') || *field == ' ')) {
    41a6c3
    -                /* This line is a continuation of the preceding line(s),
    41a6c3
    -                 * so append it to the line that we've set aside.
    41a6c3
    -                 * Note: this uses a power-of-two allocator to avoid
    41a6c3
    -                 * doing O(n) allocs and using O(n^2) space for
    41a6c3
    -                 * continuations that span many many lines.
    41a6c3
    -                 */
    41a6c3
    -                apr_size_t fold_len = last_len + len + 1; /* trailing null */
    41a6c3
     
    41a6c3
    -                if (fold_len >= (apr_size_t)(r->server->limit_req_fieldsize)) {
    41a6c3
    -                    r->status = HTTP_BAD_REQUEST;
    41a6c3
    -                    /* report what we have accumulated so far before the
    41a6c3
    -                     * overflow (last_field) as the field with the problem
    41a6c3
    -                     */
    41a6c3
    -                    apr_table_setn(r->notes, "error-notes",
    41a6c3
    -                                   apr_psprintf(r->pool,
    41a6c3
    -                                               "Size of a request header field "
    41a6c3
    -                                               "after folding "
    41a6c3
    -                                               "exceeds server limit.
    \n"
    41a6c3
    -                                               "
    \n%.*s\n
    \n",
    41a6c3
    -                                               field_name_len(last_field), 
    41a6c3
    -                                               ap_escape_html(r->pool, last_field)));
    41a6c3
    -                    ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00562)
    41a6c3
    -                                  "Request header exceeds LimitRequestFieldSize "
    41a6c3
    -                                  "after folding: %.*s",
    41a6c3
    -                                  field_name_len(last_field), last_field);
    41a6c3
    -                    return;
    41a6c3
    -                }
    41a6c3
    +        /* For all header values, and all obs-fold lines, the presence of
    41a6c3
    +         * additional whitespace is a no-op, so collapse trailing whitespace
    41a6c3
    +         * to save buffer allocation and optimize copy operations.
    41a6c3
    +         * Do not remove the last single whitespace under any condition.
    41a6c3
    +         */
    41a6c3
    +        while (len > 1 && (field[len-1] == '\t' || field[len-1] == ' ')) {
    41a6c3
    +            field[--len] = '\0';
    41a6c3
    +        }
    41a6c3
    +
    41a6c3
    +        if (*field == '\t' || *field == ' ') {
    41a6c3
    +            /* Append any newly-read obs-fold line onto the preceding
    41a6c3
    +             * last_field line we are processing
    41a6c3
    +             */
    41a6c3
    +            apr_size_t fold_len;
    41a6c3
     
    41a6c3
    +            if (last_field == NULL) {
    41a6c3
    +                r->status = HTTP_BAD_REQUEST;
    41a6c3
    +                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03442)
    41a6c3
    +                              "Line folding encountered before first"
    41a6c3
    +                              " header line");
    41a6c3
    +                return;
    41a6c3
    +            }
    41a6c3
    +
    41a6c3
    +            if (field[1] == '\0') {
    41a6c3
    +                r->status = HTTP_BAD_REQUEST;
    41a6c3
    +                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03443)
    41a6c3
    +                              "Empty folded line encountered");
    41a6c3
    +                return;
    41a6c3
    +            }
    41a6c3
    +
    41a6c3
    +            /* Leading whitespace on an obs-fold line can be
    41a6c3
    +             * similarly discarded */
    41a6c3
    +            while (field[1] == '\t' || field[1] == ' ') {
    41a6c3
    +                ++field; --len;
    41a6c3
    +            }
    41a6c3
    +
    41a6c3
    +            /* This line is a continuation of the preceding line(s),
    41a6c3
    +             * so append it to the line that we've set aside.
    41a6c3
    +             * Note: this uses a power-of-two allocator to avoid
    41a6c3
    +             * doing O(n) allocs and using O(n^2) space for
    41a6c3
    +             * continuations that span many many lines.
    41a6c3
    +             */
    41a6c3
    +            fold_len = last_len + len + 1; /* trailing null */
    41a6c3
    +
    41a6c3
    +            if (fold_len >= (apr_size_t)(r->server->limit_req_fieldsize)) {
    41a6c3
    +                r->status = HTTP_BAD_REQUEST;
    41a6c3
    +                /* report what we have accumulated so far before the
    41a6c3
    +                 * overflow (last_field) as the field with the problem
    41a6c3
    +                 */
    41a6c3
    +                apr_table_setn(r->notes, "error-notes",
    41a6c3
    +                               "Size of a request header field "
    41a6c3
    +                               "exceeds server limit.");
    41a6c3
    +                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00562)
    41a6c3
    +                              "Request header exceeds LimitRequestFieldSize "
    41a6c3
    +                              "after folding: %.*s",
    41a6c3
    +                              field_name_len(last_field), last_field);
    41a6c3
    +                return;
    41a6c3
    +            }
    41a6c3
    +
    41a6c3
    +            if (fold_len > alloc_len) {
    41a6c3
    +                char *fold_buf;
    41a6c3
    +                alloc_len += alloc_len;
    41a6c3
                     if (fold_len > alloc_len) {
    41a6c3
    -                    char *fold_buf;
    41a6c3
    -                    alloc_len += alloc_len;
    41a6c3
    -                    if (fold_len > alloc_len) {
    41a6c3
    -                        alloc_len = fold_len;
    41a6c3
    -                    }
    41a6c3
    -                    fold_buf = (char *)apr_palloc(r->pool, alloc_len);
    41a6c3
    -                    memcpy(fold_buf, last_field, last_len);
    41a6c3
    -                    last_field = fold_buf;
    41a6c3
    +                    alloc_len = fold_len;
    41a6c3
                     }
    41a6c3
    -                memcpy(last_field + last_len, field, len +1); /* +1 for nul */
    41a6c3
    -                last_len += len;
    41a6c3
    -                folded = 1;
    41a6c3
    -            }
    41a6c3
    -            else /* not a continuation line */ {
    41a6c3
    +                fold_buf = (char *)apr_palloc(r->pool, alloc_len);
    41a6c3
    +                memcpy(fold_buf, last_field, last_len);
    41a6c3
    +                last_field = fold_buf;
    41a6c3
    +            }
    41a6c3
    +            memcpy(last_field + last_len, field, len +1); /* +1 for nul */
    41a6c3
    +            /* Replace obs-fold w/ SP per RFC 7230 3.2.4 */
    41a6c3
    +            last_field[last_len] = ' ';
    41a6c3
    +            last_len += len;
    41a6c3
     
    41a6c3
    -                if (r->server->limit_req_fields
    41a6c3
    +            /* We've appended this obs-fold line to last_len, proceed to
    41a6c3
    +             * read the next input line
    41a6c3
    +             */
    41a6c3
    +            continue;
    41a6c3
    +        }
    41a6c3
    +        else if (last_field != NULL) {
    41a6c3
    +            /* Process the previous last_field header line with all obs-folded
    41a6c3
    +             * segments already concatinated (this is not operating on the
    41a6c3
    +             * most recently read input line).
    41a6c3
    +             */
    41a6c3
    +            if (r->server->limit_req_fields
    41a6c3
                         && (++fields_read > r->server->limit_req_fields)) {
    41a6c3
    -                    r->status = HTTP_BAD_REQUEST;
    41a6c3
    -                    apr_table_setn(r->notes, "error-notes",
    41a6c3
    -                                   "The number of request header fields "
    41a6c3
    -                                   "exceeds this server's limit.");
    41a6c3
    -                    ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00563)
    41a6c3
    -                                  "Number of request headers exceeds "
    41a6c3
    -                                  "LimitRequestFields");
    41a6c3
    -                    return;
    41a6c3
    -                }
    41a6c3
    +                r->status = HTTP_BAD_REQUEST;
    41a6c3
    +                apr_table_setn(r->notes, "error-notes",
    41a6c3
    +                               "The number of request header fields "
    41a6c3
    +                               "exceeds this server's limit.");
    41a6c3
    +                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00563)
    41a6c3
    +                               "Number of request headers exceeds "
    41a6c3
    +                               "LimitRequestFields");
    41a6c3
    +                return;
    41a6c3
    +            }
    41a6c3
     
    41a6c3
    -                if (!(value = strchr(last_field, ':'))) { /* Find ':' or    */
    41a6c3
    -                    r->status = HTTP_BAD_REQUEST;      /* abort bad request */
    41a6c3
    -                    apr_table_setn(r->notes, "error-notes",
    41a6c3
    -                                   apr_psprintf(r->pool,
    41a6c3
    -                                               "Request header field is "
    41a6c3
    -                                               "missing ':' separator.
    \n"
    41a6c3
    -                                               "
    \n%.*s
    \n",
    41a6c3
    -                                               (int)LOG_NAME_MAX_LEN,
    41a6c3
    -                                               ap_escape_html(r->pool,
    41a6c3
    -                                                              last_field)));
    41a6c3
    -                    ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00564)
    41a6c3
    +            if (!strict)
    41a6c3
    +            {
    41a6c3
    +                /* Not Strict ('Unsafe' mode), using the legacy parser */
    41a6c3
    +
    41a6c3
    +                if (!(value = strchr(last_field, ':'))) { /* Find ':' or */
    41a6c3
    +                    r->status = HTTP_BAD_REQUEST;   /* abort bad request */
    41a6c3
    +                    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00564)
    41a6c3
                                       "Request header field is missing ':' "
    41a6c3
                                       "separator: %.*s", (int)LOG_NAME_MAX_LEN,
    41a6c3
                                       last_field);
    41a6c3
    +
    41a6c3
                         return;
    41a6c3
                     }
    41a6c3
     
    41a6c3
    -                tmp_field = value - 1; /* last character of field-name */
    41a6c3
    +                /* last character of field-name */
    41a6c3
    +                tmp_field = value - (value > last_field ? 1 : 0);
    41a6c3
     
    41a6c3
                     *value++ = '\0'; /* NUL-terminate at colon */
    41a6c3
     
    41a6c3
    +                if (strpbrk(last_field, "\t\n\v\f\r ")) {
    41a6c3
    +                    r->status = HTTP_BAD_REQUEST;
    41a6c3
    +                    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03452)
    41a6c3
    +                                  "Request header field name presented"
    41a6c3
    +                                  " invalid whitespace");
    41a6c3
    +                    return;
    41a6c3
    +                }
    41a6c3
    +
    41a6c3
                     while (*value == ' ' || *value == '\t') {
    41a6c3
    -                    ++value;            /* Skip to start of value   */
    41a6c3
    +                     ++value;            /* Skip to start of value   */
    41a6c3
    +                }
    41a6c3
    +
    41a6c3
    +                if (strpbrk(value, "\n\v\f\r")) {
    41a6c3
    +                    r->status = HTTP_BAD_REQUEST;
    41a6c3
    +                    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03451)
    41a6c3
    +                                  "Request header field value presented"
    41a6c3
    +                                  " bad whitespace");
    41a6c3
    +                    return;
    41a6c3
                     }
    41a6c3
     
    41a6c3
    -                /* Strip LWS after field-name: */
    41a6c3
    -                while (tmp_field > last_field
    41a6c3
    -                       && (*tmp_field == ' ' || *tmp_field == '\t')) {
    41a6c3
    -                    *tmp_field-- = '\0';
    41a6c3
    +                if (tmp_field == last_field) {
    41a6c3
    +                    r->status = HTTP_BAD_REQUEST;
    41a6c3
    +                    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03453)
    41a6c3
    +                                  "Request header field name was empty");
    41a6c3
    +                    return;
    41a6c3
    +                }
    41a6c3
    +            }
    41a6c3
    +            else /* Using strict RFC7230 parsing */
    41a6c3
    +            {
    41a6c3
    +                /* Ensure valid token chars before ':' per RFC 7230 3.2.4 */
    41a6c3
    +                value = (char *)ap_scan_http_token(last_field);
    41a6c3
    +                if ((value == last_field) || *value != ':') {
    41a6c3
    +                    r->status = HTTP_BAD_REQUEST;
    41a6c3
    +                    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02426)
    41a6c3
    +                                  "Request header field name is malformed: "
    41a6c3
    +                                  "%.*s", (int)LOG_NAME_MAX_LEN, last_field);
    41a6c3
    +                    return;
    41a6c3
                     }
    41a6c3
     
    41a6c3
    -                /* Strip LWS after field-value: */
    41a6c3
    -                tmp_field = last_field + last_len - 1;
    41a6c3
    -                while (tmp_field > value
    41a6c3
    -                       && (*tmp_field == ' ' || *tmp_field == '\t')) {
    41a6c3
    -                    *tmp_field-- = '\0';
    41a6c3
    +                *value++ = '\0'; /* NUL-terminate last_field name at ':' */
    41a6c3
    +
    41a6c3
    +                while (*value == ' ' || *value == '\t') {
    41a6c3
    +                    ++value;     /* Skip LWS of value */
    41a6c3
                     }
    41a6c3
     
    41a6c3
    -                apr_table_addn(r->headers_in, last_field, value);
    41a6c3
    +                /* Find invalid, non-HT ctrl char, or the trailing NULL */
    41a6c3
    +                tmp_field = (char *)ap_scan_http_field_content(value);
    41a6c3
     
    41a6c3
    -                /* reset the alloc_len so that we'll allocate a new
    41a6c3
    -                 * buffer if we have to do any more folding: we can't
    41a6c3
    -                 * use the previous buffer because its contents are
    41a6c3
    -                 * now part of r->headers_in
    41a6c3
    +                /* Reject value for all garbage input (CTRLs excluding HT)
    41a6c3
    +                 * e.g. only VCHAR / SP / HT / obs-text are allowed per
    41a6c3
    +                 * RFC7230 3.2.6 - leave all more explicit rule enforcement
    41a6c3
    +                 * for specific header handler logic later in the cycle
    41a6c3
                      */
    41a6c3
    -                alloc_len = 0;
    41a6c3
    +                if (*tmp_field != '\0') {
    41a6c3
    +                    r->status = HTTP_BAD_REQUEST;
    41a6c3
    +                    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02427)
    41a6c3
    +                                  "Request header value is malformed: "
    41a6c3
    +                                  "%.*s", (int)LOG_NAME_MAX_LEN, value);
    41a6c3
    +                    return;
    41a6c3
    +                }
    41a6c3
    +            }
    41a6c3
    +
    41a6c3
    +            apr_table_addn(r->headers_in, last_field, value);
    41a6c3
     
    41a6c3
    -            } /* end if current line is not a continuation starting with tab */
    41a6c3
    +            /* This last_field header is now stored in headers_in,
    41a6c3
    +             * resume processing of the current input line.
    41a6c3
    +             */
    41a6c3
             }
    41a6c3
     
    41a6c3
    -        /* Found a blank line, stop. */
    41a6c3
    +        /* Found the terminating empty end-of-headers line, stop. */
    41a6c3
             if (len == 0) {
    41a6c3
                 break;
    41a6c3
             }
    41a6c3
     
    41a6c3
    -        /* Keep track of this line so that we can parse it on
    41a6c3
    -         * the next loop iteration.  (In the folded case, last_field
    41a6c3
    -         * has been updated already.)
    41a6c3
    +        /* Keep track of this new header line so that we can extend it across
    41a6c3
    +         * any obs-fold or parse it on the next loop iteration. We referenced
    41a6c3
    +         * our previously allocated buffer in r->headers_in,
    41a6c3
    +         * so allocate a fresh buffer if required.
    41a6c3
              */
    41a6c3
    -        if (!folded) {
    41a6c3
    -            last_field = field;
    41a6c3
    -            last_len = len;
    41a6c3
    -        }
    41a6c3
    +        alloc_len = 0;
    41a6c3
    +        last_field = field;
    41a6c3
    +        last_len = len;
    41a6c3
         }
    41a6c3
     
    41a6c3
         /* Combine multiple message-header fields with the same
    41a6c3
    @@ -899,7 +1197,7 @@
    41a6c3
         request_rec *r;
    41a6c3
         apr_pool_t *p;
    41a6c3
         const char *expect;
    41a6c3
    -    int access_status = HTTP_OK;
    41a6c3
    +    int access_status;
    41a6c3
         apr_bucket_brigade *tmp_bb;
    41a6c3
         apr_socket_t *csd;
    41a6c3
         apr_interval_time_t cur_timeout;
    41a6c3
    @@ -958,35 +1256,39 @@
    41a6c3
     
    41a6c3
         /* Get the request... */
    41a6c3
         if (!read_request_line(r, tmp_bb)) {
    41a6c3
    -        if (r->status == HTTP_REQUEST_URI_TOO_LARGE
    41a6c3
    -            || r->status == HTTP_BAD_REQUEST) {
    41a6c3
    +        switch (r->status) {
    41a6c3
    +        case HTTP_REQUEST_URI_TOO_LARGE:
    41a6c3
    +        case HTTP_BAD_REQUEST:
    41a6c3
    +        case HTTP_VERSION_NOT_SUPPORTED:
    41a6c3
    +        case HTTP_NOT_IMPLEMENTED:
    41a6c3
                 if (r->status == HTTP_REQUEST_URI_TOO_LARGE) {
    41a6c3
                     ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00565)
    41a6c3
                                   "request failed: client's request-line exceeds LimitRequestLine (longer than %d)",
    41a6c3
                                   r->server->limit_req_line);
    41a6c3
                 }
    41a6c3
                 else if (r->method == NULL) {
    41a6c3
    -                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00566)
    41a6c3
    -                              "request failed: invalid characters in URI");
    41a6c3
    +                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00566)
    41a6c3
    +                              "request failed: malformed request line");
    41a6c3
                 }
    41a6c3
    -            ap_send_error_response(r, 0);
    41a6c3
    +            access_status = r->status;
    41a6c3
    +            r->status = HTTP_OK;
    41a6c3
    +            ap_die(access_status, r);
    41a6c3
                 ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
    41a6c3
                 ap_run_log_transaction(r);
    41a6c3
    +            r = NULL;
    41a6c3
                 apr_brigade_destroy(tmp_bb);
    41a6c3
                 goto traceout;
    41a6c3
    -        }
    41a6c3
    -        else if (r->status == HTTP_REQUEST_TIME_OUT) {
    41a6c3
    -            ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
    41a6c3
    -            if (!r->connection->keepalives) {
    41a6c3
    +        case HTTP_REQUEST_TIME_OUT:
    41a6c3
    +            ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, NULL);
    41a6c3
    +            if (!r->connection->keepalives)
    41a6c3
                     ap_run_log_transaction(r);
    41a6c3
    -            }
    41a6c3
                 apr_brigade_destroy(tmp_bb);
    41a6c3
                 goto traceout;
    41a6c3
    +        default:
    41a6c3
    +            apr_brigade_destroy(tmp_bb);
    41a6c3
    +            r = NULL;
    41a6c3
    +            goto traceout;
    41a6c3
             }
    41a6c3
    -
    41a6c3
    -        apr_brigade_destroy(tmp_bb);
    41a6c3
    -        r = NULL;
    41a6c3
    -        goto traceout;
    41a6c3
         }
    41a6c3
     
    41a6c3
         /* We may have been in keep_alive_timeout mode, so toggle back
    41a6c3
    @@ -1003,7 +1305,7 @@
    41a6c3
         if (!r->assbackwards) {
    41a6c3
             ap_get_mime_headers_core(r, tmp_bb);
    41a6c3
             if (r->status != HTTP_OK) {
    41a6c3
    -            ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00567)
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00567)
    41a6c3
                               "request failed: error reading the headers");
    41a6c3
                 ap_send_error_response(r, 0);
    41a6c3
                 ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
    41a6c3
    @@ -1021,25 +1323,6 @@
    41a6c3
                 apr_table_unset(r->headers_in, "Content-Length");
    41a6c3
             }
    41a6c3
         }
    41a6c3
    -    else {
    41a6c3
    -        if (r->header_only) {
    41a6c3
    -            /*
    41a6c3
    -             * Client asked for headers only with HTTP/0.9, which doesn't send
    41a6c3
    -             * headers! Have to dink things just to make sure the error message
    41a6c3
    -             * comes through...
    41a6c3
    -             */
    41a6c3
    -            ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00568)
    41a6c3
    -                          "client sent invalid HTTP/0.9 request: HEAD %s",
    41a6c3
    -                          r->uri);
    41a6c3
    -            r->header_only = 0;
    41a6c3
    -            r->status = HTTP_BAD_REQUEST;
    41a6c3
    -            ap_send_error_response(r, 0);
    41a6c3
    -            ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
    41a6c3
    -            ap_run_log_transaction(r);
    41a6c3
    -            apr_brigade_destroy(tmp_bb);
    41a6c3
    -            goto traceout;
    41a6c3
    -        }
    41a6c3
    -    }
    41a6c3
     
    41a6c3
         apr_brigade_destroy(tmp_bb);
    41a6c3
     
    41a6c3
    @@ -1071,7 +1354,7 @@
    41a6c3
              * a Host: header, and the server MUST respond with 400 if it doesn't.
    41a6c3
              */
    41a6c3
             access_status = HTTP_BAD_REQUEST;
    41a6c3
    -        ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(00569)
    41a6c3
    +        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00569)
    41a6c3
                           "client sent HTTP/1.1 request without hostname "
    41a6c3
                           "(see RFC2616 section 14.23): %s", r->uri);
    41a6c3
         }
    41a6c3
    diff -uap httpd-2.4.6/server/util.c.cve8743 httpd-2.4.6/server/util.c
    41a6c3
    --- httpd-2.4.6/server/util.c.cve8743
    41a6c3
    +++ httpd-2.4.6/server/util.c
    41a6c3
    @@ -79,7 +79,7 @@
    41a6c3
      * char in here and get it to work, because if char is signed then it
    41a6c3
      * will first be sign extended.
    41a6c3
      */
    41a6c3
    -#define TEST_CHAR(c, f)        (test_char_table[(unsigned)(c)] & (f))
    41a6c3
    +#define TEST_CHAR(c, f)        (test_char_table[(unsigned char)(c)] & (f))
    41a6c3
     
    41a6c3
     /* Win32/NetWare/OS2 need to check for both forward and back slashes
    41a6c3
      * in ap_getparents() and ap_escape_url.
    41a6c3
    @@ -1449,6 +1449,37 @@
    41a6c3
         return find_list_item(p, line, tok, AP_ETAG_WEAK);
    41a6c3
     }
    41a6c3
     
    41a6c3
    +/* Scan a string for HTTP VCHAR/obs-text characters including HT and SP
    41a6c3
    + * (as used in header values, for example, in RFC 7230 section 3.2)
    41a6c3
    + * returning the pointer to the first non-HT ASCII ctrl character.
    41a6c3
    + */
    41a6c3
    +AP_DECLARE(const char *) ap_scan_http_field_content(const char *ptr)
    41a6c3
    +{
    41a6c3
    +    for ( ; !TEST_CHAR(*ptr, T_HTTP_CTRLS); ++ptr) ;
    41a6c3
    +
    41a6c3
    +    return ptr;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
    +/* Scan a string for HTTP token characters, returning the pointer to
    41a6c3
    + * the first non-token character.
    41a6c3
    + */
    41a6c3
    +AP_DECLARE(const char *) ap_scan_http_token(const char *ptr)
    41a6c3
    +{
    41a6c3
    +    for ( ; !TEST_CHAR(*ptr, T_HTTP_TOKEN_STOP); ++ptr) ;
    41a6c3
    +
    41a6c3
    +    return ptr;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
    +/* Scan a string for visible ASCII (0x21-0x7E) or obstext (0x80+)
    41a6c3
    + * and return a pointer to the first ctrl/space character encountered.
    41a6c3
    + */
    41a6c3
    +AP_DECLARE(const char *) ap_scan_vchar_obstext(const char *ptr)
    41a6c3
    +{
    41a6c3
    +    for ( ; TEST_CHAR(*ptr, T_VCHAR_OBSTEXT); ++ptr) ;
    41a6c3
    +
    41a6c3
    +    return ptr;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
     /* Retrieve a token, spacing over it and returning a pointer to
    41a6c3
      * the first non-white byte afterwards.  Note that these tokens
    41a6c3
      * are delimited by semis and commas; and can also be delimited
    41a6c3
    diff -uap httpd-2.4.6/server/vhost.c.cve8743 httpd-2.4.6/server/vhost.c
    41a6c3
    --- httpd-2.4.6/server/vhost.c.cve8743
    41a6c3
    +++ httpd-2.4.6/server/vhost.c
    41a6c3
    @@ -685,6 +685,116 @@
    41a6c3
      * run-time vhost matching functions
    41a6c3
      */
    41a6c3
     
    41a6c3
    +static apr_status_t fix_hostname_v6_literal(request_rec *r, char *host)
    41a6c3
    +{
    41a6c3
    +    char *dst;
    41a6c3
    +    int double_colon = 0;
    41a6c3
    +
    41a6c3
    +    for (dst = host; *dst; dst++) {
    41a6c3
    +        if (apr_isxdigit(*dst)) {
    41a6c3
    +            if (apr_isupper(*dst)) {
    41a6c3
    +                *dst = apr_tolower(*dst);
    41a6c3
    +            }
    41a6c3
    +        }
    41a6c3
    +        else if (*dst == ':') {
    41a6c3
    +            if (*(dst + 1) == ':') {
    41a6c3
    +                if (double_colon)
    41a6c3
    +                    return APR_EINVAL;
    41a6c3
    +                double_colon = 1;
    41a6c3
    +            }
    41a6c3
    +            else if (*(dst + 1) == '.') {
    41a6c3
    +                return APR_EINVAL;
    41a6c3
    +            }
    41a6c3
    +        }
    41a6c3
    +        else if (*dst == '.') {
    41a6c3
    +            /* For IPv4-mapped IPv6 addresses like ::FFFF:129.144.52.38 */
    41a6c3
    +            if (*(dst + 1) == ':' || *(dst + 1) == '.')
    41a6c3
    +                return APR_EINVAL;
    41a6c3
    +        }
    41a6c3
    +        else {
    41a6c3
    +            return APR_EINVAL;
    41a6c3
    +        }
    41a6c3
    +    }
    41a6c3
    +    return APR_SUCCESS;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
    +static apr_status_t fix_hostname_non_v6(request_rec *r, char *host)
    41a6c3
    +{
    41a6c3
    +    char *dst;
    41a6c3
    +
    41a6c3
    +    for (dst = host; *dst; dst++) {
    41a6c3
    +        if (apr_islower(*dst)) {
    41a6c3
    +            /* leave char unchanged */
    41a6c3
    +        }
    41a6c3
    +        else if (*dst == '.') {
    41a6c3
    +            if (*(dst + 1) == '.') {
    41a6c3
    +                return APR_EINVAL;
    41a6c3
    +            }
    41a6c3
    +        }
    41a6c3
    +        else if (apr_isupper(*dst)) {
    41a6c3
    +            *dst = apr_tolower(*dst);
    41a6c3
    +        }
    41a6c3
    +        else if (*dst == '/' || *dst == '\\') {
    41a6c3
    +            return APR_EINVAL;
    41a6c3
    +        }
    41a6c3
    +    }
    41a6c3
    +    /* strip trailing gubbins */
    41a6c3
    +    if (dst > host && dst[-1] == '.') {
    41a6c3
    +        dst[-1] = '\0';
    41a6c3
    +    }
    41a6c3
    +    return APR_SUCCESS;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
    +/*
    41a6c3
    + * If strict mode ever becomes the default, this should be folded into
    41a6c3
    + * fix_hostname_non_v6()
    41a6c3
    + */
    41a6c3
    +static apr_status_t strict_hostname_check(request_rec *r, char *host)
    41a6c3
    +{
    41a6c3
    +    char *ch;
    41a6c3
    +    int is_dotted_decimal = 1, leading_zeroes = 0, dots = 0;
    41a6c3
    +
    41a6c3
    +    for (ch = host; *ch; ch++) {
    41a6c3
    +        if (!apr_isascii(*ch)) {
    41a6c3
    +            goto bad;
    41a6c3
    +        }
    41a6c3
    +        else if (apr_isalpha(*ch) || *ch == '-') {
    41a6c3
    +            is_dotted_decimal = 0;
    41a6c3
    +        }
    41a6c3
    +        else if (ch[0] == '.') {
    41a6c3
    +            dots++;
    41a6c3
    +            if (ch[1] == '0' && apr_isdigit(ch[2]))
    41a6c3
    +                leading_zeroes = 1;
    41a6c3
    +        }
    41a6c3
    +        else if (!apr_isdigit(*ch)) {
    41a6c3
    +           /* also takes care of multiple Host headers by denying commas */
    41a6c3
    +            goto bad;
    41a6c3
    +        }
    41a6c3
    +    }
    41a6c3
    +    if (is_dotted_decimal) {
    41a6c3
    +        if (host[0] == '.' || (host[0] == '0' && apr_isdigit(host[1])))
    41a6c3
    +            leading_zeroes = 1;
    41a6c3
    +        if (leading_zeroes || dots != 3) {
    41a6c3
    +            /* RFC 3986 7.4 */
    41a6c3
    +            goto bad;
    41a6c3
    +        }
    41a6c3
    +    }
    41a6c3
    +    else {
    41a6c3
    +        /* The top-level domain must start with a letter (RFC 1123 2.1) */
    41a6c3
    +        while (ch > host && *ch != '.')
    41a6c3
    +            ch--;
    41a6c3
    +        if (ch[0] == '.' && ch[1] != '\0' && !apr_isalpha(ch[1]))
    41a6c3
    +            goto bad;
    41a6c3
    +    }
    41a6c3
    +    return APR_SUCCESS;
    41a6c3
    +
    41a6c3
    +bad:
    41a6c3
    +    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02415)
    41a6c3
    +                  "[strict] Invalid host name '%s'%s%.6s",
    41a6c3
    +                  host, *ch ? ", problem near: " : "", ch);
    41a6c3
    +    return APR_EINVAL;
    41a6c3
    +}
    41a6c3
    +
    41a6c3
     /* Lowercase and remove any trailing dot and/or :port from the hostname,
    41a6c3
      * and check that it is sane.
    41a6c3
      *
    41a6c3
    @@ -698,79 +808,90 @@
    41a6c3
      * Instead we just check for filesystem metacharacters: directory
    41a6c3
      * separators / and \ and sequences of more than one dot.
    41a6c3
      */
    41a6c3
    -static void fix_hostname(request_rec *r)
    41a6c3
    +static int fix_hostname(request_rec *r, const char *host_header,
    41a6c3
    +                        unsigned http_conformance)
    41a6c3
     {
    41a6c3
    +    const char *src;
    41a6c3
         char *host, *scope_id;
    41a6c3
    -    char *dst;
    41a6c3
         apr_port_t port;
    41a6c3
         apr_status_t rv;
    41a6c3
         const char *c;
    41a6c3
    +    int is_v6literal = 0;
    41a6c3
    +    int strict = (http_conformance != AP_HTTP_CONFORMANCE_UNSAFE);
    41a6c3
     
    41a6c3
    -    /* According to RFC 2616, Host header field CAN be blank. */
    41a6c3
    -    if (!*r->hostname) {
    41a6c3
    -        return;
    41a6c3
    +    src = host_header ? host_header : r->hostname;
    41a6c3
    +
    41a6c3
    +    /* According to RFC 2616, Host header field CAN be blank */
    41a6c3
    +    if (!*src) {
    41a6c3
    +        return is_v6literal;
    41a6c3
         }
    41a6c3
     
    41a6c3
         /* apr_parse_addr_port will interpret a bare integer as a port
    41a6c3
          * which is incorrect in this context.  So treat it separately.
    41a6c3
          */
    41a6c3
    -    for (c = r->hostname; apr_isdigit(*c); ++c);
    41a6c3
    -    if (!*c) {  /* pure integer */
    41a6c3
    -        return;
    41a6c3
    +    for (c = src; apr_isdigit(*c); ++c);
    41a6c3
    +    if (!*c) {
    41a6c3
    +        /* pure integer */
    41a6c3
    +        if (strict) {
    41a6c3
    +            /* RFC 3986 7.4 */
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02416)
    41a6c3
    +                         "[strict] purely numeric host names not allowed: %s",
    41a6c3
    +                         src);
    41a6c3
    +            goto bad_nolog;
    41a6c3
    +        }
    41a6c3
    +        r->hostname = src;
    41a6c3
    +        return is_v6literal;
    41a6c3
    +    }
    41a6c3
    +
    41a6c3
    +    if (host_header) {
    41a6c3
    +        rv = apr_parse_addr_port(&host, &scope_id, &port, src, r->pool);
    41a6c3
    +        if (rv != APR_SUCCESS || scope_id)
    41a6c3
    +            goto bad;
    41a6c3
    +        if (port) {
    41a6c3
    +            /* Don't throw the Host: header's port number away:
    41a6c3
    +               save it in parsed_uri -- ap_get_server_port() needs it! */
    41a6c3
    +            /* @@@ XXX there should be a better way to pass the port.
    41a6c3
    +             *         Like r->hostname, there should be a r->portno
    41a6c3
    +             */
    41a6c3
    +            r->parsed_uri.port = port;
    41a6c3
    +            r->parsed_uri.port_str = apr_itoa(r->pool, (int)port);
    41a6c3
    +        }
    41a6c3
    +        if (host_header[0] == '[')
    41a6c3
    +            is_v6literal = 1;
    41a6c3
    +    }
    41a6c3
    +    else {
    41a6c3
    +        /*
    41a6c3
    +         * Already parsed, surrounding [ ] (if IPv6 literal) and :port have
    41a6c3
    +         * already been removed.
    41a6c3
    +         */
    41a6c3
    +        host = apr_pstrdup(r->pool, r->hostname);
    41a6c3
    +        if (ap_strchr(host, ':') != NULL)
    41a6c3
    +            is_v6literal = 1;
    41a6c3
         }
    41a6c3
     
    41a6c3
    -    rv = apr_parse_addr_port(&host, &scope_id, &port, r->hostname, r->pool);
    41a6c3
    -    if (rv != APR_SUCCESS || scope_id) {
    41a6c3
    -        goto bad;
    41a6c3
    +    if (is_v6literal) {
    41a6c3
    +        rv = fix_hostname_v6_literal(r, host);
    41a6c3
         }
    41a6c3
    -
    41a6c3
    -    if (port) {
    41a6c3
    -        /* Don't throw the Host: header's port number away:
    41a6c3
    -           save it in parsed_uri -- ap_get_server_port() needs it! */
    41a6c3
    -        /* @@@ XXX there should be a better way to pass the port.
    41a6c3
    -         *         Like r->hostname, there should be a r->portno
    41a6c3
    -         */
    41a6c3
    -        r->parsed_uri.port = port;
    41a6c3
    -        r->parsed_uri.port_str = apr_itoa(r->pool, (int)port);
    41a6c3
    +    else {
    41a6c3
    +        rv = fix_hostname_non_v6(r, host);
    41a6c3
    +        if (strict && rv == APR_SUCCESS)
    41a6c3
    +            rv = strict_hostname_check(r, host);
    41a6c3
         }
    41a6c3
    +    if (rv != APR_SUCCESS)
    41a6c3
    +        goto bad;
    41a6c3
     
    41a6c3
    -    /* if the hostname is an IPv6 numeric address string, it was validated
    41a6c3
    -     * already; otherwise, further validation is needed
    41a6c3
    -     */
    41a6c3
    -    if (r->hostname[0] != '[') {
    41a6c3
    -        for (dst = host; *dst; dst++) {
    41a6c3
    -            if (apr_islower(*dst)) {
    41a6c3
    -                /* leave char unchanged */
    41a6c3
    -            }
    41a6c3
    -            else if (*dst == '.') {
    41a6c3
    -                if (*(dst + 1) == '.') {
    41a6c3
    -                    goto bad;
    41a6c3
    -                }
    41a6c3
    -            }
    41a6c3
    -            else if (apr_isupper(*dst)) {
    41a6c3
    -                *dst = apr_tolower(*dst);
    41a6c3
    -            }
    41a6c3
    -            else if (*dst == '/' || *dst == '\\') {
    41a6c3
    -                goto bad;
    41a6c3
    -            }
    41a6c3
    -        }
    41a6c3
    -        /* strip trailing gubbins */
    41a6c3
    -        if (dst > host && dst[-1] == '.') {
    41a6c3
    -            dst[-1] = '\0';
    41a6c3
    -        }
    41a6c3
    -    }
    41a6c3
         r->hostname = host;
    41a6c3
    -    return;
    41a6c3
    +    return is_v6literal;
    41a6c3
     
    41a6c3
     bad:
    41a6c3
    -    r->status = HTTP_BAD_REQUEST;
    41a6c3
         ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00550)
    41a6c3
                       "Client sent malformed Host header: %s",
    41a6c3
    -                  r->hostname);
    41a6c3
    -    return;
    41a6c3
    +                  src);
    41a6c3
    +bad_nolog:
    41a6c3
    +    r->status = HTTP_BAD_REQUEST;
    41a6c3
    +    return is_v6literal;
    41a6c3
     }
    41a6c3
     
    41a6c3
    -
    41a6c3
     /* return 1 if host matches ServerName or ServerAliases */
    41a6c3
     static int matches_aliases(server_rec *s, const char *host)
    41a6c3
     {
    41a6c3
    @@ -980,15 +1101,76 @@
    41a6c3
         }
    41a6c3
     }
    41a6c3
     
    41a6c3
    +static APR_INLINE const char *construct_host_header(request_rec *r,
    41a6c3
    +                                                    int is_v6literal)
    41a6c3
    +{
    41a6c3
    +    struct iovec iov[5];
    41a6c3
    +    apr_size_t nvec = 0;
    41a6c3
    +    /*
    41a6c3
    +     * We cannot use ap_get_server_name/port here, because we must
    41a6c3
    +     * ignore UseCanonicalName/Port.
    41a6c3
    +     */
    41a6c3
    +    if (is_v6literal) {
    41a6c3
    +        iov[nvec].iov_base = "[";
    41a6c3
    +        iov[nvec].iov_len = 1;
    41a6c3
    +        nvec++;
    41a6c3
    +    }
    41a6c3
    +    iov[nvec].iov_base = (void *)r->hostname;
    41a6c3
    +    iov[nvec].iov_len = strlen(r->hostname);
    41a6c3
    +    nvec++;
    41a6c3
    +    if (is_v6literal) {
    41a6c3
    +        iov[nvec].iov_base = "]";
    41a6c3
    +        iov[nvec].iov_len = 1;
    41a6c3
    +        nvec++;
    41a6c3
    +    }
    41a6c3
    +    if (r->parsed_uri.port_str) {
    41a6c3
    +        iov[nvec].iov_base = ":";
    41a6c3
    +        iov[nvec].iov_len = 1;
    41a6c3
    +        nvec++;
    41a6c3
    +        iov[nvec].iov_base = r->parsed_uri.port_str;
    41a6c3
    +        iov[nvec].iov_len = strlen(r->parsed_uri.port_str);
    41a6c3
    +        nvec++;
    41a6c3
    +    }
    41a6c3
    +    return apr_pstrcatv(r->pool, iov, nvec, NULL);
    41a6c3
    +}
    41a6c3
     
    41a6c3
     AP_DECLARE(void) ap_update_vhost_from_headers(request_rec *r)
    41a6c3
     {
    41a6c3
    -    /* must set this for HTTP/1.1 support */
    41a6c3
    -    if (r->hostname || (r->hostname = apr_table_get(r->headers_in, "Host"))) {
    41a6c3
    -        fix_hostname(r);
    41a6c3
    -        if (r->status != HTTP_OK)
    41a6c3
    -            return;
    41a6c3
    +    core_server_config *conf = ap_get_core_module_config(r->server->module_config);
    41a6c3
    +    const char *host_header = apr_table_get(r->headers_in, "Host");
    41a6c3
    +    int is_v6literal = 0;
    41a6c3
    +    int have_hostname_from_url = 0;
    41a6c3
    +
    41a6c3
    +    if (r->hostname) {
    41a6c3
    +        /*
    41a6c3
    +         * If there was a host part in the Request-URI, ignore the 'Host'
    41a6c3
    +         * header.
    41a6c3
    +         */
    41a6c3
    +        have_hostname_from_url = 1;
    41a6c3
    +        is_v6literal = fix_hostname(r, NULL, conf->http_conformance);
    41a6c3
    +    }
    41a6c3
    +    else if (host_header != NULL) {
    41a6c3
    +        is_v6literal = fix_hostname(r, host_header, conf->http_conformance);
    41a6c3
    +    }
    41a6c3
    +    if (r->status != HTTP_OK)
    41a6c3
    +        return;
    41a6c3
    +
    41a6c3
    +    if (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE) {
    41a6c3
    +        /*
    41a6c3
    +         * If we have both hostname from an absoluteURI and a Host header,
    41a6c3
    +         * we must ignore the Host header (RFC 2616 5.2).
    41a6c3
    +         * To enforce this, we reset the Host header to the value from the
    41a6c3
    +         * request line.
    41a6c3
    +         */
    41a6c3
    +        if (have_hostname_from_url && host_header != NULL) {
    41a6c3
    +            const char *repl = construct_host_header(r, is_v6literal);
    41a6c3
    +            apr_table_set(r->headers_in, "Host", repl);
    41a6c3
    +            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02417)
    41a6c3
    +                          "Replacing host header '%s' with host '%s' given "
    41a6c3
    +                          "in the request uri", host_header, repl);
    41a6c3
    +        }
    41a6c3
         }
    41a6c3
    +
    41a6c3
         /* check if we tucked away a name_chain */
    41a6c3
         if (r->connection->vhost_lookup_data) {
    41a6c3
             if (r->hostname)