summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorEric Covener <covener@apache.org>2020-02-07 18:14:05 +0100
committerEric Covener <covener@apache.org>2020-02-07 18:14:05 +0100
commitc1ac12fa3b94bf1aabf16acad38afdb4198f8f23 (patch)
treec037dda4d7abf4de6262e5e3ac383ffbe0e88eeb /server
parentfactor out default regex flags (diff)
downloadapache2-c1ac12fa3b94bf1aabf16acad38afdb4198f8f23.tar.xz
apache2-c1ac12fa3b94bf1aabf16acad38afdb4198f8f23.zip
factor out TE=chunked checking
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1873748 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server')
-rw-r--r--server/protocol.c3
-rw-r--r--server/util.c44
2 files changed, 40 insertions, 7 deletions
diff --git a/server/protocol.c b/server/protocol.c
index a0209715a2..7313b0a190 100644
--- a/server/protocol.c
+++ b/server/protocol.c
@@ -1430,8 +1430,7 @@ request_rec *ap_read_request(conn_rec *conn)
* the final encoding ...; the server MUST respond with the 400
* (Bad Request) status code and then close the connection".
*/
- if (!(ap_cstr_casecmp(tenc, "chunked") == 0 /* fast path */
- || ap_find_last_token(r->pool, tenc, "chunked"))) {
+ if (!ap_is_chunked(r->pool, tenc)) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02539)
"client sent unknown Transfer-Encoding "
"(%s): %s", tenc, r->uri);
diff --git a/server/util.c b/server/util.c
index 044b073bf5..7603895e02 100644
--- a/server/util.c
+++ b/server/util.c
@@ -1709,14 +1709,13 @@ AP_DECLARE(int) ap_find_token(apr_pool_t *p, const char *line, const char *tok)
}
}
-
-AP_DECLARE(int) ap_find_last_token(apr_pool_t *p, const char *line,
- const char *tok)
+static const char *find_last_token(apr_pool_t *p, const char *line,
+ const char *tok)
{
int llen, tlen, lidx;
if (!line)
- return 0;
+ return NULL;
llen = strlen(line);
tlen = strlen(tok);
@@ -1724,9 +1723,44 @@ AP_DECLARE(int) ap_find_last_token(apr_pool_t *p, const char *line,
if (lidx < 0 ||
(lidx > 0 && !(apr_isspace(line[lidx - 1]) || line[lidx - 1] == ',')))
+ return NULL;
+
+ if (ap_cstr_casecmpn(&line[lidx], tok, tlen) == 0) {
+ return &line[lidx];
+ }
+ return NULL;
+}
+
+AP_DECLARE(int) ap_find_last_token(apr_pool_t *p, const char *line,
+ const char *tok)
+{
+ return find_last_token(p, line, tok) != NULL;
+}
+
+AP_DECLARE(int) ap_is_chunked(apr_pool_t *p, const char *line)
+{
+ const char *s;
+
+ if (!line)
return 0;
+ if (!ap_cstr_casecmp(line, "chunked")) {
+ return 1;
+ }
- return (ap_cstr_casecmpn(&line[lidx], tok, tlen) == 0);
+ s = find_last_token(p, line, "chunked");
+
+ if (!s) return 0;
+
+ /* eat spaces right-to-left to see what precedes "chunked" */
+ while (--s > line) {
+ if (*s != ' ') break;
+ }
+
+ /* found delim, or leading ws (input wasn't parsed by httpd as a header) */
+ if (*s == ',' || *s == ' ') {
+ return 1;
+ }
+ return 0;
}
AP_DECLARE(char *) ap_escape_shell_cmd(apr_pool_t *p, const char *str)