]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stktable: fix potential build issue in smp_to_stkey (2nd try)
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 15 Jan 2025 08:43:51 +0000 (09:43 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 15 Jan 2025 13:04:31 +0000 (14:04 +0100)
As discussed in GH #2838, the previous fix f399dbf
("MINOR: stktable: fix potential build issue in smp_to_stkey") which
attempted to remove conversion ambiguity and prevent build warning proved
to be insufficient.

This time, we implement Willy's suggestion, which is to use an union to
perform the conversion.

Hopefully this should fix GH #2838. If that's the case (and only in that
case), then this patch may be backported with f399dbf (else the patch
won't apply) anywhere b59d1fd ("BUG/MINOR: stktable: fix big-endian
compatiblity in smp_to_stkey()") was backported.

src/stick_table.c

index 852995a1a5f7f5c60b2f260ab729a915f3779100..9dbcadfc761d823088babd93fe3b92fe2893774f 100644 (file)
@@ -1495,13 +1495,19 @@ struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t)
 
        case SMP_T_SINT:
        {
-               uint *_sint = (uint *)&smp->data.u.sint;
+               union {
+                       uint32_t u32;
+                       int64_t s64;
+               } conv;
 
                /* The stick table require a 32bit unsigned int, "sint" is a
                 * signed 64 it, so we can convert it inplace.
                 */
-               *_sint = (uint)smp->data.u.sint;
-               static_table_key.key = _sint;
+               conv.s64 = 0;
+               conv.u32 = smp->data.u.sint;
+               smp->data.u.sint = conv.s64;
+
+               static_table_key.key = &smp->data.u.sint;
                static_table_key.key_len = 4;
                break;
        }