From 422e38bd828d1cddf55fe923ec7ebd269583d8ec Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Thu, 9 Jan 2025 09:05:43 +0100 Subject: [PATCH] BUG/MINOR: stktable: fix big-endian compatiblity in smp_to_stkey() 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. (cherry picked from commit b59d1fd911045c37b3fc88795a1f2c1947e6e59d) Signed-off-by: Christopher Faulet --- src/stick_table.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/stick_table.c b/src/stick_table.c index f49fb0a..82416c4 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -1464,13 +1464,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)) -- 1.7.10.4