]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: map: don't store exp_replace() result in the trash's length
authorWilly Tarreau <w@1wt.eu>
Wed, 22 Aug 2018 02:55:43 +0000 (04:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 22 Aug 2018 03:16:33 +0000 (05:16 +0200)
By convenience or laziness we used to store exp_replace()'s return code
into str->data. The result checks applied there compare str->data to -1
while it's now unsigned since commit 843b7cb ("MEDIUM: chunks: make the
chunk struct's fields match the buffer struct"). Let's clean this up
and test the result itself without storing it first.

No backport is needed.

src/map.c

index d2df22e21212e0ce02577217e06cc86587fd2386..d94b0f2605c43134e8e1d2d71a196ab0b4057343 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -186,6 +186,7 @@ static int sample_conv_map(const struct arg *arg_p, struct sample *smp, void *pr
                        /* In the regm case, merge the sample with the input. */
                        if ((long)private == PAT_MATCH_REGM) {
                                struct buffer *tmptrash;
+                               int len;
 
                                /* Copy the content of the sample because it could
                                   be scratched by incoming get_trash_chunk */
@@ -201,12 +202,14 @@ static int sample_conv_map(const struct arg *arg_p, struct sample *smp, void *pr
                                tmptrash->area[tmptrash->data] = 0;
 
                                str = get_trash_chunk();
-                               str->data = exp_replace(str->area, str->size,
-                                                       tmptrash->area,
-                                                       pat->data->u.str.area,
-                                                       (regmatch_t *)smp->ctx.a[0]);
-                               if (str->data == -1)
+                               len = exp_replace(str->area, str->size,
+                                                 tmptrash->area,
+                                                 pat->data->u.str.area,
+                                                 (regmatch_t *)smp->ctx.a[0]);
+                               if (len == -1)
                                        return 0;
+
+                               str->data = len;
                                smp->data.u.str = *str;
                                return 1;
                        }