5a9fda464cc31b9857b8faedb2c6c278ec978faf
[openwrt-packages.git] /
1 commit 41dc8432f87622145390dc1b1467a5ee14ba184c
2 Author: Christopher Faulet <cfaulet@haproxy.com>
3 Date:   Tue Jun 18 09:49:16 2019 +0200
4
5     BUG/MEDIUM: htx: Fully update HTX message when the block value is changed
6     
7     Everywhere the value length of a block is changed, calling the function
8     htx_set_blk_value_len(), the HTX message must be updated. But at many places,
9     because of the recent changes in the HTX structure, this update was only
10     partially done. tail_addr and head_addr values were not systematically updated.
11     
12     In fact, the function htx_set_blk_value_len() was designed as an internal
13     function to the HTX API. And we used it from outside by convenience. But it is
14     really painfull and error prone to let the caller update the HTX message. So
15     now, we use the function htx_change_blk_value_len() wherever is possible. It
16     changes the value length of a block and updates the HTX message accordingly.
17     
18     This patch must be backported to 2.0.
19     
20     (cherry picked from commit 3e2638ee04407a1d9e9376f0c518f67fca7deaa4)
21     Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
22
23 diff --git a/src/h2.c b/src/h2.c
24 index 32c1ef16..990d602b 100644
25 --- a/src/h2.c
26 +++ b/src/h2.c
27 @@ -736,8 +736,7 @@ int h2_make_htx_request(struct http_hdr *list, struct htx *htx, unsigned int *ms
28                         if (tl > fs)
29                                 goto fail;
30  
31 -                       htx_set_blk_value_len(blk, tl);
32 -                       htx->data += vl+2;
33 +                       htx_change_blk_value_len(htx, blk, tl);
34                         *(char *)(htx_get_blk_ptr(htx, blk) + bs + 0) = ';';
35                         *(char *)(htx_get_blk_ptr(htx, blk) + bs + 1) = ' ';
36                         memcpy(htx_get_blk_ptr(htx, blk) + bs + 2, list[ck].v.ptr, vl);
37 diff --git a/src/http_htx.c b/src/http_htx.c
38 index 7322b337..bc26e5ba 100644
39 --- a/src/http_htx.c
40 +++ b/src/http_htx.c
41 @@ -461,10 +461,7 @@ int http_remove_header(struct htx *htx, struct http_hdr_ctx *ctx)
42         }
43         /* Update the block content and its len */
44         memmove(start, start+len, v.len-len);
45 -       htx_set_blk_value_len(blk, v.len-len);
46 -
47 -       /* Update HTX msg */
48 -       htx->data -= len;
49 +       htx_change_blk_value_len(htx, blk, v.len-len);
50  
51         /* Finally update the ctx */
52         ctx->value.ptr = start;
53 diff --git a/src/htx.c b/src/htx.c
54 index bfd136f4..81492598 100644
55 --- a/src/htx.c
56 +++ b/src/htx.c
57 @@ -406,15 +406,8 @@ void htx_truncate(struct htx *htx, uint32_t offset)
58                         offset -= sz;
59                         continue;
60                 }
61 -               if (type == HTX_BLK_DATA) {
62 -                       htx_set_blk_value_len(blk, offset);
63 -                       htx->data -= (sz - offset);
64 -
65 -                       if (blk->addr+sz == htx->tail_addr)
66 -                               htx->tail_addr -= offset;
67 -                       else if (blk->addr+sz == htx->head_addr)
68 -                               htx->head_addr -= offset;
69 -               }
70 +               if (type == HTX_BLK_DATA)
71 +                       htx_change_blk_value_len(htx, blk, offset);
72                 offset = 0;
73         }
74         while (blk)
75 @@ -522,14 +515,7 @@ struct htx_blk *htx_add_data_atonce(struct htx *htx, struct ist data)
76         /* Append data and update the block itself */
77         ptr = htx_get_blk_ptr(htx, tailblk);
78         memcpy(ptr+sz, data.ptr, len);
79 -       htx_set_blk_value_len(tailblk, sz+len);
80 -
81 -       /* Update HTTP message */
82 -       htx->data += len;
83 -       if (tailblk->addr+sz == htx->tail_addr)
84 -               htx->tail_addr += len;
85 -       else if (tailblk->addr+sz == htx->head_addr)
86 -               htx->head_addr += len;
87 +       htx_change_blk_value_len(htx, tailblk, sz+len);
88  
89         if (data.len == len) {
90                 blk = tailblk;
91 @@ -988,14 +974,7 @@ size_t htx_add_data(struct htx *htx, const struct ist data)
92         /* Append data and update the block itself */
93         ptr = htx_get_blk_ptr(htx, tailblk);
94         memcpy(ptr + sz, data.ptr, len);
95 -       htx_set_blk_value_len(tailblk, sz + len);
96 -
97 -       /* Update HTTP message */
98 -       htx->data += len;
99 -       if (tailblk->addr+sz == htx->tail_addr)
100 -               htx->tail_addr += len;
101 -       else if (tailblk->addr+sz == htx->head_addr)
102 -               htx->head_addr += len;
103 +       htx_change_blk_value_len(htx, tailblk, sz+len);
104  
105         BUG_ON((int32_t)htx->tail_addr < 0);
106         BUG_ON((int32_t)htx->head_addr < 0);
107 diff --git a/src/proto_htx.c b/src/proto_htx.c
108 index 7f501366..d821e38c 100644
109 --- a/src/proto_htx.c
110 +++ b/src/proto_htx.c
111 @@ -4314,10 +4314,8 @@ static void htx_manage_client_side_cookies(struct stream *s, struct channel *req
112                         hdr_end = (preserve_hdr ? del_from : hdr_beg);
113                 }
114                 if ((hdr_end - hdr_beg) != ctx.value.len) {
115 -                       if (hdr_beg != hdr_end) {
116 -                               htx_set_blk_value_len(ctx.blk, hdr_end - hdr_beg);
117 -                               htx->data -= ctx.value.len - (hdr_end - hdr_beg);
118 -                       }
119 +                       if (hdr_beg != hdr_end)
120 +                               htx_change_blk_value_len(htx, ctx.blk, hdr_end - hdr_beg);
121                         else
122                                 http_remove_header(htx, &ctx);
123                 }
124 @@ -4495,8 +4493,7 @@ static void htx_manage_server_side_cookies(struct stream *s, struct channel *res
125                                 next         += stripped_before;
126                                 hdr_end      += stripped_before;
127  
128 -                               htx_set_blk_value_len(ctx.blk, hdr_end - hdr_beg);
129 -                               htx->data -= ctx.value.len - (hdr_end - hdr_beg);
130 +                               htx_change_blk_value_len(htx, ctx.blk, hdr_end - hdr_beg);
131                                 ctx.value.len = hdr_end - hdr_beg;
132                         }
133  
git clone https://git.99rst.org/PROJECT