]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: sample: Always consider zero size string samples as unsafe
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 18 Feb 2021 09:22:48 +0000 (10:22 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 18 Feb 2021 13:58:43 +0000 (14:58 +0100)
smp_is_safe() function is used to be sure a sample may be safely
modified. For string samples, a test is performed to verify if there is a
null-terminated byte. If not, one is added, if possible. It means if the
sample is not const and if there is some free space in the buffer, after
data. However, we must not try to read the null-terminated byte if the
string sample is too long (data >= size) or if the size is equal to
zero. This last test was not performed. Thus it was possible to consider a
string sample as safe by testing a byte outside the buffer.

Now, a zero size string sample is always considered as unsafe and is
duplicated when smp_make_safe() is called.

This patch must be backported in all stable versions.

include/haproxy/sample.h

index 4a0561015fd68f0350fdfeb6db2b69fad8c0d9a6..e5378b03cd689c87fb2ab7f79c80c80d8e090745 100644 (file)
@@ -97,13 +97,13 @@ int smp_is_safe(struct sample *smp)
                /* Fall through */
 
        case SMP_T_STR:
-               if (smp->data.u.str.size && smp->data.u.str.data >= smp->data.u.str.size)
+               if (!smp->data.u.str.size || smp->data.u.str.data >= smp->data.u.str.size)
                        return 0;
 
                if (smp->data.u.str.area[smp->data.u.str.data] == 0)
                        return 1;
 
-               if (!smp->data.u.str.size || (smp->flags & SMP_F_CONST))
+               if (smp->flags & SMP_F_CONST)
                        return 0;
 
                smp->data.u.str.area[smp->data.u.str.data] = 0;