From: Phil Sutter Date: Fri, 31 May 2019 14:17:42 +0000 (+0200) Subject: mnl: Initialize fd_set before select(), not after X-Git-Tag: v0.9.1~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59d301ec80264a907918028c590f7f172003a995;p=thirdparty%2Fnftables.git mnl: Initialize fd_set before select(), not after 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 Signed-off-by: Pablo Neira Ayuso --- diff --git a/src/mnl.c b/src/mnl.c index 4eba27895..b32e4190b 100644 --- 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; }