1 commit c1620a52a3def02b4837376385c416c03ca874c4
2 Author: Kevin Zhu <ipandtcp@gmail.com>
3 Date: Fri Apr 26 14:00:01 2019 +0800
5 BUG/MEDIUM: spoe: arg len encoded in previous frag frame but len changed
7 Fragmented arg will do fetch at every encode time, each fetch may get
8 different result if SMP_F_MAY_CHANGE, for example res.payload, but
9 the length already encoded in first fragment of the frame, that will
10 cause SPOA decode failed and waste resources.
12 This patch must be backported to 1.9 and 1.8.
14 (cherry picked from commit f7f54280c8106e92a55243f5d60f8587e79602d1)
15 Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
16 (cherry picked from commit 3a838e526cdbc00ded5362e66f1ef3a441abc3c1)
17 Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
19 diff --git a/include/proto/spoe.h b/include/proto/spoe.h
20 index 002cf7d7..2cdca10b 100644
21 --- a/include/proto/spoe.h
22 +++ b/include/proto/spoe.h
23 @@ -121,7 +121,7 @@ spoe_decode_buffer(char **buf, char *end, char **str, uint64_t *len)
24 * many bytes has been encoded. If <*off> is zero at the end, it means that all
25 * data has been encoded. */
27 -spoe_encode_data(struct sample *smp, unsigned int *off, char **buf, char *end)
28 +spoe_encode_data(unsigned int *len, struct sample *smp, unsigned int *off, char **buf, char *end)
32 @@ -183,15 +183,16 @@ spoe_encode_data(struct sample *smp, unsigned int *off, char **buf, char *end)
33 ret = spoe_encode_frag_buffer(chk->str, chk->len, &p, end);
39 /* The sample has been fragmented, encode remaining data */
40 - ret = MIN(chk->len - *off, end - p);
41 + ret = MIN(*len - *off, end - p);
42 memcpy(p, chk->str + *off, ret);
45 /* Now update <*off> */
46 - if (ret + *off != chk->len)
47 + if (ret + *off != *len)
51 diff --git a/include/types/spoe.h b/include/types/spoe.h
52 index 53e7200c..cfaa42f8 100644
53 --- a/include/types/spoe.h
54 +++ b/include/types/spoe.h
55 @@ -304,6 +304,7 @@ struct spoe_context {
56 struct spoe_message *curmsg; /* SPOE message from which to resume encoding */
57 struct spoe_arg *curarg; /* SPOE arg in <curmsg> from which to resume encoding */
58 unsigned int curoff; /* offset in <curarg> from which to resume encoding */
59 + unsigned int curlen; /* length of <curarg> need to be encode, for SMP_F_MAY_CHANGE data */
60 unsigned int flags; /* SPOE_FRM_FL_* */
61 } frag_ctx; /* Info about fragmented frames, valid on if SPOE_CTX_FL_FRAGMENTED is set */
63 diff --git a/src/flt_spoe.c b/src/flt_spoe.c
64 index f6109778..0c0b3794 100644
67 @@ -2172,6 +2172,7 @@ spoe_encode_message(struct stream *s, struct spoe_context *ctx,
68 list_for_each_entry(arg, &msg->args, list) {
69 ctx->frag_ctx.curarg = arg;
70 ctx->frag_ctx.curoff = UINT_MAX;
71 + ctx->frag_ctx.curlen = 0;
74 if (ctx->frag_ctx.curoff != UINT_MAX)
75 @@ -2186,7 +2187,7 @@ spoe_encode_message(struct stream *s, struct spoe_context *ctx,
77 /* Fetch the arguement value */
78 smp = sample_process(s->be, s->sess, s, dir|SMP_OPT_FINAL, arg->expr, NULL);
79 - ret = spoe_encode_data(smp, &ctx->frag_ctx.curoff, buf, end);
80 + ret = spoe_encode_data(&ctx->frag_ctx.curlen, smp, &ctx->frag_ctx.curoff, buf, end);
81 if (ret == -1 || ctx->frag_ctx.curoff)