1 commit 41dc8432f87622145390dc1b1467a5ee14ba184c
2 Author: Christopher Faulet <cfaulet@haproxy.com>
3 Date: Tue Jun 18 09:49:16 2019 +0200
5 BUG/MEDIUM: htx: Fully update HTX message when the block value is changed
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.
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.
18 This patch must be backported to 2.0.
20 (cherry picked from commit 3e2638ee04407a1d9e9376f0c518f67fca7deaa4)
21 Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
23 diff --git a/src/h2.c b/src/h2.c
24 index 32c1ef16..990d602b 100644
27 @@ -736,8 +736,7 @@ int h2_make_htx_request(struct http_hdr *list, struct htx *htx, unsigned int *ms
31 - htx_set_blk_value_len(blk, tl);
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
41 @@ -461,10 +461,7 @@ int http_remove_header(struct htx *htx, struct http_hdr_ctx *ctx)
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);
47 - /* Update HTX msg */
49 + htx_change_blk_value_len(htx, blk, v.len-len);
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
57 @@ -406,15 +406,8 @@ void htx_truncate(struct htx *htx, uint32_t offset)
61 - if (type == HTX_BLK_DATA) {
62 - htx_set_blk_value_len(blk, offset);
63 - htx->data -= (sz - offset);
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;
70 + if (type == HTX_BLK_DATA)
71 + htx_change_blk_value_len(htx, blk, offset);
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);
81 - /* Update HTTP message */
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);
89 if (data.len == len) {
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);
97 - /* Update HTTP message */
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);
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);
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);
119 + if (hdr_beg != hdr_end)
120 + htx_change_blk_value_len(htx, ctx.blk, hdr_end - hdr_beg);
122 http_remove_header(htx, &ctx);
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;
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;