]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
mnl: Initialize fd_set before select(), not after
authorPhil Sutter <phil@nwl.cc>
Fri, 31 May 2019 14:17:42 +0000 (16:17 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 31 May 2019 16:07:25 +0000 (18:07 +0200)
Calling FD_SET() in between return of select() and call to FD_ISSET()
effectively renders the whole thing useless: FD_ISSET() will always
return true no matter what select() actually did.

Fixes: a72315d2bad47 ("src: add rule batching support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/mnl.c

index 4eba2789513d7d03c9c67da4c304d5f1a8487338..b32e4190b150507e82ed4c77954e03a90089342b 100644 (file)
--- a/src/mnl.c
+++ b/src/mnl.c
@@ -349,12 +349,12 @@ int mnl_batch_talk(struct netlink_ctx *ctx, struct list_head *err_list,
                if (ret == -1)
                        mnl_err_list_node_add(err_list, errno, nlh->nlmsg_seq);
 
+               FD_ZERO(&readfds);
+               FD_SET(fd, &readfds);
+
                ret = select(fd+1, &readfds, NULL, NULL, &tv);
                if (ret == -1)
                        return -1;
-
-               FD_ZERO(&readfds);
-               FD_SET(fd, &readfds);
        }
        return 0;
 }