BUG/MINOR: peers: fix data_type bit computation more than 32 data_types
authorEmeric Brun <ebrun@haproxy.com>
Thu, 1 Jul 2021 16:54:05 +0000 (18:54 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 6 Jul 2021 16:14:20 +0000 (18:14 +0200)
This patch fixes the computation of the bit of the current data_type
in some part of code of peer protocol where the computation is limited
to 32bits whereas the bitfield of data_types can support 64bits.

Without this patch it could result in bugs when we will define more
than 32 data_types.

Backport is useless because there is currently less than 32 data_types

(cherry picked from commit 08b0f6780c45099b8d03bfd9e398d3f51519e667)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 45f12b06b491b433fdb951ba851284e46901a917)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/peers.c

index 68fd6a2..fe50172 100644 (file)
@@ -842,10 +842,10 @@ static int peer_prepare_switchmsg(char *msg, size_t size, struct peer_prep_param
                                case STD_T_UINT:
                                case STD_T_ULL:
                                case STD_T_DICT:
-                                       data |= 1 << data_type;
+                                       data |= 1ULL << data_type;
                                        break;
                                case STD_T_FRQP:
-                                       data |= 1 << data_type;
+                                       data |= 1ULL << data_type;
                                        intencode(data_type, &chunkq);
                                        intencode(st->table->data_arg[data_type].u, &chunkq);
                                        break;
@@ -1654,7 +1654,7 @@ static int peer_treat_updatemsg(struct appctx *appctx, struct peer *p, int updt,
        for (data_type = 0 ; data_type < STKTABLE_DATA_TYPES ; data_type++) {
                uint64_t decoded_int;
 
-               if (!((1 << data_type) & st->remote_data))
+               if (!((1ULL << data_type) & st->remote_data))
                        continue;
 
                decoded_int = intdecode(msg_cur, msg_end);