From 73a900b94742b67be377aa47fbcbea9e267628a3 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 25 Feb 2021 14:38:16 +0100 Subject: libndp,ndptool: use poll() instead of select() select() doesn't support file descriptors greater than 1023. If the program has many files open, the socket descriptor can be > 1023 and then FD_SET(fd, &rfds) causes a buffer overflow. Switch to poll() and ppoll() which don't have this limitation. Signed-off-by: Beniamino Galvani Signed-off-by: Jiri Pirko --- libndp/libndp.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'libndp') diff --git a/libndp/libndp.c b/libndp/libndp.c index 06a3d23..6314717 100644 --- a/libndp/libndp.c +++ b/libndp/libndp.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -2107,22 +2107,20 @@ int ndp_call_eventfd_handler(struct ndp *ndp) NDP_EXPORT int ndp_callall_eventfd_handler(struct ndp *ndp) { - fd_set rfds; - int fdmax; - struct timeval tv; - int fd = ndp_get_eventfd(ndp); + struct pollfd pfd; int ret; int err; - memset(&tv, 0, sizeof(tv)); - FD_ZERO(&rfds); - FD_SET(fd, &rfds); - fdmax = fd + 1; + pfd = (struct pollfd) { + .fd = ndp_get_eventfd(ndp), + .events = POLLIN, + }; + while (true) { - ret = select(fdmax, &rfds, NULL, NULL, &tv); + ret = poll(&pfd, 1, 0); if (ret == -1) return -errno; - if (!FD_ISSET(fd, &rfds)) + if (!(pfd.revents & POLLIN)) return 0; err = ndp_call_eventfd_handler(ndp); if (err) -- cgit v1.2.1