]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: sample: fix host_only and port_only on empty input
authorGihyeon Ryu <rlgusryu@gmail.com>
Wed, 11 Nov 2026 10:00:12 +0000 (10:00 +0000)
committerOlivier Houchard <cognet@ci0.org>
Fri, 13 Nov 2026 15:55:27 +0000 (16:55 +0100)
sample_conv_host_only() and sample_conv_port_only() scan backwards from
area + data - 1. With an empty sample whose area is NULL, as returned by
req.body for a request without a body, this pointer is (char *)-1, the
first dereference faults and the worker dies (SIGSEGV, also in release
builds). A configuration applying these converters to req.body can thus
be stopped by a plain "GET /".

Both converters now return early on an empty input, with an empty string
and 0 respectively.

This should be backported to 2.8 and later.

src/sample.c

index 877e8e02cab8a10498493a881f519e3ed3fbbece..548d8c232e49f97c482fe1f17208ee567d1a307c 100644 (file)
@@ -4152,6 +4152,12 @@ static int sample_conv_host_only(const struct arg *arg_p, struct sample *smp, vo
        char *end = smp->data.u.str.area + smp->data.u.str.data - 1;
        char *p;
 
+       /* an empty input may come with a NULL area */
+       if (!smp->data.u.str.data) {
+               smp->data.type = SMP_T_STR;
+               return 1;
+       }
+
        for (p = end; p >= beg; p--) {
                if (*p == ':' || *p == ']')
                        break;
@@ -4178,6 +4184,13 @@ static int sample_conv_port_only(const struct arg *arg_p, struct sample *smp, vo
        char *end = smp->data.u.str.area + smp->data.u.str.data - 1;
        char *p;
 
+       /* see sample_conv_host_only() */
+       if (!smp->data.u.str.data) {
+               smp->data.type = SMP_T_SINT;
+               smp->data.u.sint = 0;
+               return 1;
+       }
+
        for (p = end; p >= beg; p--) {
                if (*p == ':' || *p == ']')
                        break;