9ef95076520bee905a1200669a99381bfd0fbbae
[openwrt-packages.git] /
1 commit c1620a52a3def02b4837376385c416c03ca874c4
2 Author: Kevin Zhu <ipandtcp@gmail.com>
3 Date:   Fri Apr 26 14:00:01 2019 +0800
4
5     BUG/MEDIUM: spoe: arg len encoded in previous frag frame but len changed
6     
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.
11     
12     This patch must be backported to 1.9 and 1.8.
13     
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>
18
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. */
26  static inline int
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)
29  {
30         char *p = *buf;
31         int   ret;
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);
34                                 if (ret == -1)
35                                         return -1;
36 +                               *len = chk->len;
37                         }
38                         else {
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);
43                                 p += ret;
44                         }
45                         /* Now update <*off> */
46 -                       if (ret + *off != chk->len)
47 +                       if (ret + *off != *len)
48                                 *off += ret;
49                         else
50                                 *off = 0;
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 */
62  };
63 diff --git a/src/flt_spoe.c b/src/flt_spoe.c
64 index f6109778..0c0b3794 100644
65 --- a/src/flt_spoe.c
66 +++ b/src/flt_spoe.c
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;
72  
73           encode_argument:
74                 if (ctx->frag_ctx.curoff != UINT_MAX)
75 @@ -2186,7 +2187,7 @@ spoe_encode_message(struct stream *s, struct spoe_context *ctx,
76  
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)
82                         goto too_big;
83         }
git clone https://git.99rst.org/PROJECT