From cdbe12073817c58a0dd56c32f1f0ab6149de8fd2 Mon Sep 17 00:00:00 2001 From: jean-airoldie <25088801+jean-airoldie@users.noreply.github.com> Date: Thu, 2 May 2019 06:07:06 -0400 Subject: [PATCH] Problem: No invalid pointer handling for zmq_poller_fd Solution: Add some and document it. --- doc/zmq_poller.txt | 2 ++ src/zmq.cpp | 8 +++++++- tests/test_poller.cpp | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/doc/zmq_poller.txt b/doc/zmq_poller.txt index 435ca1b4..fed45f5a 100644 --- a/doc/zmq_poller.txt +++ b/doc/zmq_poller.txt @@ -249,6 +249,8 @@ No registered event was signalled before the timeout was reached. On _zmq_poller_fd: *EINVAL*:: The poller has no associated file descriptor. +*EFAULT*:: +The provided 'poller' did not point to a valid poller. EXAMPLE ------- diff --git a/src/zmq.cpp b/src/zmq.cpp index 521d9939..5dc1fc40 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -1280,7 +1280,13 @@ int zmq_poller_wait_all (void *poller_, int zmq_poller_fd (void *poller_) { - return static_cast (poller_)->signaler_fd (); + if (!poller_ + || !(static_cast (poller_)->check_tag ())) { + errno = EFAULT; + return -1; + } else { + return static_cast (poller_)->signaler_fd (); + } } // Peer-specific state diff --git a/tests/test_poller.cpp b/tests/test_poller.cpp index d812e7cd..8170bc75 100644 --- a/tests/test_poller.cpp +++ b/tests/test_poller.cpp @@ -195,6 +195,12 @@ void test_null_poller_pointers_wait_all_indirect () EFAULT, zmq_poller_wait_all (&null_poller, &event, 1, 0)); } +void test_null_poller_pointer_poller_fd () +{ + void *null_poller = NULL; + TEST_ASSERT_FAILURE_ERRNO (EFAULT, zmq_poller_fd (&null_poller)); +} + void test_null_socket_pointers () { void *poller = zmq_poller_new (); @@ -269,6 +275,8 @@ void test_call_poller_fd_no_signaler () TEST_ASSERT_FAILURE_ERRNO (EINVAL, zmq_poller_fd (poller)); + TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_destroy (&poller)); + test_context_socket_close (socket); } @@ -284,6 +292,8 @@ void test_call_poller_fd () TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_fd (poller)); + TEST_ASSERT_SUCCESS_ERRNO (zmq_poller_destroy (&poller)); + test_context_socket_close (socket); } @@ -656,6 +666,7 @@ int main (void) RUN_TEST (test_null_poller_pointers_wait_indirect); RUN_TEST (test_null_poller_pointers_wait_all_direct); RUN_TEST (test_null_poller_pointers_wait_all_indirect); + RUN_TEST (test_null_poller_pointer_poller_fd); RUN_TEST (test_null_socket_pointers);