From 51b1fcedebbec17fd38b8b1c1de10c7572d24ec8 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 25 Jul 2022 15:42:41 +0200 Subject: [PATCH] DEBUG: fd: detect possibly invalid tgid in fd_insert() Since the API is still a bit young, let's make sure nobody tries to assign and FD to a group not strictly 1..MAX_TGROUPS as that would indicate a bug. Note: some of these might be relaxed to BUG_ON_HOT() in the future --- include/haproxy/fd.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/haproxy/fd.h b/include/haproxy/fd.h index b57076bef..e8ef4f3bc 100644 --- a/include/haproxy/fd.h +++ b/include/haproxy/fd.h @@ -436,6 +436,7 @@ static inline void fd_insert(int fd, void *owner, void (*iocb)(int fd), int tgid BUG_ON(fd < 0 || fd >= global.maxsock); BUG_ON(fdtab[fd].owner != NULL); BUG_ON(fdtab[fd].state != 0); + BUG_ON(tgid < 1 || tgid > MAX_TGROUPS); thread_mask &= tg->threads_enabled; BUG_ON(thread_mask == 0);