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
This commit is contained in:
sigiesec 2017-08-22 18:40:04 +02:00
parent c1a4cfdd9f
commit 74303b08e6
2 changed files with 14 additions and 14 deletions

View File

@ -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 ()) { if (!poller_ || !((zmq::socket_poller_t*)poller_)->check_tag ()) {
errno = EFAULT; errno = EFAULT;
return -1; 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) { 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 // wait_all returns number of events, but we return 0 for any success
return rc >= 0 ? 0 : rc; 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 ()) { if (!poller_ || !((zmq::socket_poller_t*)poller_)->check_tag ()) {
errno = EFAULT; errno = EFAULT;
return -1; return -1;
} }
if (!events_) {
errno = EFAULT;
return -1;
}
if (n_events < 0) { if (n_events < 0) {
errno = EINVAL; errno = EINVAL;
return -1; 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; return rc;
} }

View File

@ -144,15 +144,11 @@ void test_null_event_pointers (void *ctx)
int rc = zmq_poller_add (poller, socket, NULL, ZMQ_POLLIN); int rc = zmq_poller_add (poller, socket, NULL, ZMQ_POLLIN);
assert (rc == 0); assert (rc == 0);
// TODO this causes an assertion, which is not consistent with the rc = zmq_poller_wait (poller, NULL, 0);
// behavior for other NULL parameters
#if 0
rc = zmq_poller_wait(poller, NULL, 0);
assert (rc == -1 && errno == EFAULT); assert (rc == -1 && errno == EFAULT);
rc = zmq_poller_wait_all (poller, NULL, 1, 0); rc = zmq_poller_wait_all (poller, NULL, 1, 0);
assert (rc == -1 && errno == EFAULT); assert (rc == -1 && errno == EFAULT);
#endif
// TODO this causes an assertion, which is not consistent if the number // 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 // of events may be 0, the pointer should be allowed to by NULL in that