4a8c2b1b800de6830798b4b2df7312977ca54a49
[openwrt-packages.git] /
1 commit e313c1bd5901b721bdfd23714c432235625a87a8
2 Author: Christopher Faulet <cfaulet@haproxy.com>
3 Date:   Mon Jan 6 13:41:01 2020 +0100
4
5     BUG/MINOR: h1: Report the right error position when a header value is invalid
6     
7     During H1 messages parsing, when the parser has finished to parse a full header
8     line, some tests are performed on its value, depending on its name, to be sure
9     it is valid. The content-length is checked and converted in integer and the host
10     header is also checked. If an error occurred during this step, the error
11     position must point on the header value. But from the parser point of view, we
12     are already on the start of the next header. Thus the effective reported
13     position in the error capture is the beginning of the unparsed header line. It
14     is a bit confusing when we try to figure out why a message is rejected.
15     
16     Now, the parser state is updated to point on the invalid value. This way, the
17     error position really points on the right position.
18     
19     This patch must be backported as far as 1.9.
20     
21     (cherry picked from commit 1703478e2dd6bd12bb03b0a0fdcc7cd4a611dafc)
22     Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
23
24 diff --git a/src/h1.c b/src/h1.c
25 index 15827db56..63fbee8c0 100644
26 --- a/src/h1.c
27 +++ b/src/h1.c
28 @@ -819,6 +819,7 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
29  
30                                         if (ret < 0) {
31                                                 state = H1_MSG_HDR_L2_LWS;
32 +                                               ptr = v.ptr; /* Set ptr on the error */
33                                                 goto http_msg_invalid;
34                                         }
35                                         else if (ret == 0) {
36 @@ -841,16 +842,18 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
37                                                 if (authority.len && !isteqi(v, authority)) {
38                                                         if (h1m->err_pos < -1) {
39                                                                 state = H1_MSG_HDR_L2_LWS;
40 +                                                               ptr = v.ptr; /* Set ptr on the error */
41                                                                 goto http_msg_invalid;
42                                                         }
43                                                         if (h1m->err_pos == -1) /* capture the error pointer */
44 -                                                               h1m->err_pos = ptr - start + skip; /* >= 0 now */
45 +                                                               h1m->err_pos = v.ptr - start + skip; /* >= 0 now */
46                                                 }
47                                                 host_idx = hdr_count;
48                                         }
49                                         else {
50                                                 if (!isteqi(v, hdr[host_idx].v)) {
51                                                         state = H1_MSG_HDR_L2_LWS;
52 +                                                       ptr = v.ptr; /* Set ptr on the error */
53                                                         goto http_msg_invalid;
54                                                 }
55                                                 /* if the same host, skip it */
git clone https://git.99rst.org/PROJECT