]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: stktable: fix big-endian compatiblity in smp_to_stkey()
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 9 Jan 2025 08:05:43 +0000 (09:05 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 9 Jan 2025 09:56:43 +0000 (10:56 +0100)
When smp_to_stkey() deals with SINT samples, since stick-tables deals with
32 bits integers while SINT sample is 64 bit integer, inplace conversion
was done in smp_to_stkey. For that the 64 bit integer was truncated before
the key would point to it. Unfortunately this only works on little endian
architectures because with big endian ones, the key would point to the
wrong 32bit range.

To fix the issue and make the conversion endian-proof, let's re-assign
the sample as 32bit integer before the key points to it.

Thanks to Willy for having spotted the bug and suggesting the above fix.

It should be backported to all stable versions.

src/stick_table.c

index 792a8da9e2cc232647f756f799693020e2f29579..5fbe564c1a01edd392e4ca370d8f43b385eb13ae 100644 (file)
@@ -1475,13 +1475,17 @@ struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t)
                break;
 
        case SMP_T_SINT:
+       {
+               uint *_sint = (uint *)&smp->data.u.sint;
+
                /* The stick table require a 32bit unsigned int, "sint" is a
                 * signed 64 it, so we can convert it inplace.
                 */
-               smp->data.u.sint = (unsigned int)smp->data.u.sint;
-               static_table_key.key = &smp->data.u.sint;
+               *_sint = smp->data.u.sint;
+               static_table_key.key = _sint;
                static_table_key.key_len = 4;
                break;
+       }
 
        case SMP_T_STR:
                if (!smp_make_safe(smp))