diff --git a/include/haproxy/fd.h b/include/haproxy/fd.h index 40ef38f73..8bf30cd25 100644 --- a/include/haproxy/fd.h +++ b/include/haproxy/fd.h @@ -319,6 +319,11 @@ static inline void fd_insert(int fd, void *owner, void (*iocb)(int fd), unsigned { extern void sock_conn_iocb(int); + /* This must never happen and would definitely indicate a bug, in + * addition to overwriting some unexpected memory areas. + */ + BUG_ON(fd < 0 || fd >= global.maxsock); + fdtab[fd].owner = owner; fdtab[fd].iocb = iocb; fdtab[fd].state = 0; diff --git a/src/fd.c b/src/fd.c index 30fefc473..c2dfcf1d6 100644 --- a/src/fd.c +++ b/src/fd.c @@ -336,6 +336,11 @@ void _fd_delete_orphan(int fd) */ void fd_delete(int fd) { + /* This must never happen and would definitely indicate a bug, in + * addition to overwriting some unexpected memory areas. + */ + BUG_ON(fd < 0 || fd >= global.maxsock); + /* we must postpone removal of an FD that may currently be in use * by another thread. This can happen in the following two situations: * - after a takeover, the owning thread closes the connection but