From 74303b08e688811db99ac3d34416c40f0722416b Mon Sep 17 00:00:00 2001 From: sigiesec Date: Tue, 22 Aug 2017 18:40:04 +0200 Subject: [PATCH] Problem: calling zmq_poller_wait* with NULL events causes an assertion, as opposed to other NULL arguments, which return an error Solution: return EFAULT when such an operation is attempted --- src/zmq.cpp | 22 +++++++++++++--------- tests/test_poller.cpp | 6 +----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/zmq.cpp b/src/zmq.cpp index c2d0fdda..3f7b83c8 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -1349,38 +1349,42 @@ int zmq_poller_remove_fd (void *poller_, int fd_) } -int zmq_poller_wait (void *poller_, zmq_poller_event_t *event, long timeout_) +int zmq_poller_wait (void *poller_, zmq_poller_event_t *event_, long timeout_) { if (!poller_ || !((zmq::socket_poller_t*)poller_)->check_tag ()) { errno = EFAULT; return -1; } + if (!event_) { + errno = EFAULT; + return -1; + } - zmq_assert (event != NULL); - - int rc = zmq_poller_wait_all(poller_, event, 1, timeout_); + int rc = zmq_poller_wait_all(poller_, event_, 1, timeout_); if (rc < 0) { - memset (event, 0, sizeof(zmq_poller_event_t)); + memset (event_, 0, sizeof(zmq_poller_event_t)); } // wait_all returns number of events, but we return 0 for any success return rc >= 0 ? 0 : rc; } -int zmq_poller_wait_all (void *poller_, zmq_poller_event_t *events, int n_events, long timeout_) +int zmq_poller_wait_all (void *poller_, zmq_poller_event_t *events_, int n_events, long timeout_) { if (!poller_ || !((zmq::socket_poller_t*)poller_)->check_tag ()) { errno = EFAULT; return -1; } + if (!events_) { + errno = EFAULT; + return -1; + } if (n_events < 0) { errno = EINVAL; return -1; } - zmq_assert (events != NULL); - - int rc = ((zmq::socket_poller_t*)poller_)->wait ((zmq::socket_poller_t::event_t *)events, n_events, timeout_); + int rc = ((zmq::socket_poller_t*)poller_)->wait ((zmq::socket_poller_t::event_t *)events_, n_events, timeout_); return rc; } diff --git a/tests/test_poller.cpp b/tests/test_poller.cpp index 45b90160..cdfddaaa 100644 --- a/tests/test_poller.cpp +++ b/tests/test_poller.cpp @@ -144,15 +144,11 @@ void test_null_event_pointers (void *ctx) int rc = zmq_poller_add (poller, socket, NULL, ZMQ_POLLIN); assert (rc == 0); - // TODO this causes an assertion, which is not consistent with the - // behavior for other NULL parameters -#if 0 - rc = zmq_poller_wait(poller, NULL, 0); + rc = zmq_poller_wait (poller, NULL, 0); assert (rc == -1 && errno == EFAULT); rc = zmq_poller_wait_all (poller, NULL, 1, 0); assert (rc == -1 && errno == EFAULT); -#endif // TODO this causes an assertion, which is not consistent if the number // of events may be 0, the pointer should be allowed to by NULL in that