diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2021-02-25 14:38:16 +0100 |
---|---|---|
committer | Jiri Pirko <jiri@nvidia.com> | 2021-03-05 08:08:18 +0100 |
commit | 73a900b94742b67be377aa47fbcbea9e267628a3 (patch) | |
tree | ab060558a34802ea0527962fe903684b68d1aa66 /libndp/libndp.c | |
parent | 3fc2ed78edb5deae0381d022bedc22ffd00d50cb (diff) | |
download | libndp-73a900b94742b67be377aa47fbcbea9e267628a3.tar.gz |
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 <bgalvani@redhat.com>
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Diffstat (limited to 'libndp/libndp.c')
-rw-r--r-- | libndp/libndp.c | 20 |
1 files changed, 9 insertions, 11 deletions
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 <errno.h> #include <ctype.h> #include <sys/socket.h> -#include <sys/select.h> +#include <poll.h> #include <netinet/in.h> #include <netinet/icmp6.h> #include <arpa/inet.h> @@ -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) |