]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: http-conv: Fix url_enc() to not crush const samples
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 8 Apr 2022 08:04:05 +0000 (10:04 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 8 Apr 2022 08:12:59 +0000 (10:12 +0200)
url_enc() encodes an input string by calling encode_string(). To do so, it
adds a trailing '\0' to the sample string. However it never restores the
sample string at the end. It is a problem for const samples. The sample
string may be in the middle of a buffer. For instance, the HTTP headers
values are concerned.

However, instead of modifying the sample string, it is easier to rely on
encode_chunk() function. It does the same but on a buffer.

This patch must be backported as far as 2.2.

src/http_conv.c

index 121a4989ba74e11d946f9e3825810b11da01b8cd..f33336aae453b70c4d67e2a451d57a8c1d9fdd39 100644 (file)
@@ -324,16 +324,13 @@ static int sample_conv_url_enc(const struct arg *args, struct sample *smp, void
        enc_type = ENC_QUERY;
        enc_type = args->data.sint;
 
-       /* Add final \0 required by encode_string() */
-       smp->data.u.str.area[smp->data.u.str.data] = '\0';
-
        if (enc_type == ENC_QUERY)
                encode_map = query_encode_map;
        else
                return 0;
 
-       ret = encode_string(trash->area, trash->area + trash->size, '%',
-                           encode_map, smp->data.u.str.area);
+       ret = encode_chunk(trash->area, trash->area + trash->size, '%',
+                          encode_map, &smp->data.u.str);
        if (ret == NULL || *ret != '\0')
                return 0;
        trash->data = ret - trash->area;