]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: Add BUG_ON checks on fd_insert()
authorEmeric Brun <ebrun@haproxy.com>
Fri, 1 Jul 2022 11:57:39 +0000 (04:57 -0700)
committerWilly Tarreau <w@1wt.eu>
Tue, 5 Jul 2022 03:18:51 +0000 (05:18 +0200)
This patch adds two BUG_ON on fd_insert() into the fdtab checking
if the fd has been correctly re-initialized into the fdtab
before a new insert.

It will raise a BUG if we try to insert the same fd multiple times
without an intermediate fd_delete().

First one checks that the owner for this fd in fdtab was reset to NULL.

Second one checks that the state flags for this fd in fdtab was reset
to 0.

This patch could be backported on version >= 2.4

include/haproxy/fd.h

index eaee211aac6694e58bb66c9069a888fc86c3dbd4..fb16cc84ab76c61bd484d0ddb83144591314a65d 100644 (file)
@@ -332,6 +332,8 @@ static inline void fd_insert(int fd, void *owner, void (*iocb)(int fd), unsigned
         * addition to overwriting some unexpected memory areas.
         */
        BUG_ON(fd < 0 || fd >= global.maxsock);
+       BUG_ON(fdtab[fd].owner != NULL);
+       BUG_ON(fdtab[fd].state != 0);
 
        fdtab[fd].owner = owner;
        fdtab[fd].iocb = iocb;