From 51a84c15ded2d70985c9d971ebdf3f3c9c18d590 Mon Sep 17 00:00:00 2001 From: Martin Lucina Date: Sat, 4 Sep 2010 16:12:33 +0200 Subject: [PATCH] zmq::select_t, zmq_poll(): assert if FD_SETSIZE reached Ensure that 0MQ does not attempt to call select() on more than FD_SETSIZE file descriptors. --- src/select.cpp | 4 ++++ src/zmq.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/select.cpp b/src/select.cpp index 7345cbb6..59eb83e0 100644 --- a/src/select.cpp +++ b/src/select.cpp @@ -65,6 +65,10 @@ zmq::select_t::handle_t zmq::select_t::add_fd (fd_t fd_, i_poll_events *events_) fd_entry_t entry = {fd_, events_}; fds.push_back (entry); + // Ensure we do not attempt to select () on more than FD_SETSIZE + // file descriptors. + zmq_assert (fds.size () <= FD_SETSIZE); + // Start polling on errors. FD_SET (fd_, &source_set_err); diff --git a/src/zmq.cpp b/src/zmq.cpp index 342a8a63..8b21d4be 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -530,6 +530,10 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) zmq::fd_t maxfd = zmq::retired_fd; zmq::fd_t notify_fd = zmq::retired_fd; + // Ensure we do not attempt to select () on more than FD_SETSIZE + // file descriptors. + zmq_assert (nitems_ <= FD_SETSIZE); + for (int i = 0; i != nitems_; i++) { // 0MQ sockets.