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 /utils | |
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 'utils')
-rw-r--r-- | utils/Makefile.am | 2 | ||||
-rw-r--r-- | utils/ndptool.c | 22 |
2 files changed, 10 insertions, 14 deletions
diff --git a/utils/Makefile.am b/utils/Makefile.am index cca00c2..75e452c 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -2,7 +2,7 @@ MAINTAINERCLEANFILES = Makefile.in ACLOCAL_AMFLAGS = -I m4 -AM_CFLAGS = -I${top_srcdir}/include +AM_CFLAGS = -I${top_srcdir}/include -D_GNU_SOURCE ndptool_LDADD = $(top_builddir)/libndp/libndp.la diff --git a/utils/ndptool.c b/utils/ndptool.c index 662ff01..618f167 100644 --- a/utils/ndptool.c +++ b/utils/ndptool.c @@ -28,7 +28,7 @@ #include <arpa/inet.h> #include <errno.h> #include <ndp.h> -#include <sys/select.h> +#include <poll.h> enum verbosity_level { VERB1, @@ -59,13 +59,10 @@ static void empty_signal_handler(int signal) static int run_main_loop(struct ndp *ndp) { - fd_set rfds; - fd_set rfds_tmp; - int fdmax; + struct pollfd pfd; int ret; struct sigaction siginfo; sigset_t mask; - int ndp_fd; int err = 0; sigemptyset(&siginfo.sa_mask); @@ -100,23 +97,22 @@ static int run_main_loop(struct ndp *ndp) sigemptyset(&mask); - FD_ZERO(&rfds); - ndp_fd = ndp_get_eventfd(ndp); - FD_SET(ndp_fd, &rfds); - fdmax = ndp_fd + 1; + pfd = (struct pollfd) { + .fd = ndp_get_eventfd(ndp), + .events = POLLIN, + }; for (;;) { - rfds_tmp = rfds; - ret = pselect(fdmax, &rfds_tmp, NULL, NULL, NULL, &mask); + ret = ppoll(&pfd, 1, NULL, &mask); if (ret == -1) { if (errno == EINTR) { goto out; } - pr_err("Select failed\n"); + pr_err("Poll failed\n"); err = -errno; goto out; } - if (FD_ISSET(ndp_fd, &rfds_tmp)) { + if (pfd.revents & POLLIN) { err = ndp_call_eventfd_handler(ndp); if (err) { pr_err("ndp eventfd handler call failed\n"); |