]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: thread: fix extraneous shift in the thread_set parser
authorWilly Tarreau <w@1wt.eu>
Mon, 6 Feb 2023 17:01:50 +0000 (18:01 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 6 Feb 2023 17:01:50 +0000 (18:01 +0100)
AurĂ©lien reported a bug making a statement such as "thread 2-2" fail for
a config made of exactly 2 threads. What happens is that the parser for
the "thread" keyword scans a range of thread numbers from either 1..64
or 0,-1,-2 for special values, and presets the bit masks accordingly in
the thread set, except that due to the 1..64 range, the shift length must
be reduced by one. Not doing this causes empty masks for single-bit values
that are exactly equal to the number of threads in the group and fails to
properly parse.

No backport is needed as this was introduced in 2.8-dev3 by commit
bef43dfa6 ("MINOR: thread: add a simple thread_set API").

src/thread.c

index 489c841645a5bb988da0c0eaac0099c16861903e..95d979bb1903857d3598ac23ad50eb81a486ec38 100644 (file)
@@ -1522,7 +1522,7 @@ int parse_thread_set(const char *arg, struct thread_set *ts, char **err)
 
                                if (max >= min) {
                                        for (v = min; v <= max; v++)
-                                               ts->rel[tg - 1] |= 1UL << v;
+                                               ts->rel[tg - 1] |= 1UL << (v - 1);
                                } else {
                                        memset(&ts->rel[tg - 1],
                                               (max == 0) ? 0xff /* all */ : (max == -1) ? 0x55 /* odd */: 0xaa /* even */,
@@ -1532,7 +1532,7 @@ int parse_thread_set(const char *arg, struct thread_set *ts, char **err)
                                /* absolute thread numbers */
                                if (max >= min) {
                                        for (v = min; v <= max; v++)
-                                               ts->abs[v / LONGBITS] |= 1UL << (v % LONGBITS);
+                                               ts->abs[(v - 1) / LONGBITS] |= 1UL << ((v - 1) % LONGBITS);
                                } else {
                                        memset(&ts->abs,
                                               (max == 0) ? 0xff /* all */ : (max == -1) ? 0x55 /* odd */: 0xaa /* even */,