From 792ffe4d7a851df9fecdf9d47d942dddcfa92993 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Thu, 10 Sep 2020 22:30:00 +0100 Subject: [PATCH] Problem: zmq_ctx_get API broken Solution: restore EINVAL as errno on unknown option. Broken by https://github.com/zeromq/libzmq/pull/3642 which started to return EFAULT instead --- src/zmq.cpp | 11 ++++------- tests/test_ctx_options.cpp | 9 +++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/zmq.cpp b/src/zmq.cpp index 59e235a9..2c2e3d52 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -195,14 +195,11 @@ int zmq_ctx_set_ext (void *ctx_, int zmq_ctx_get (void *ctx_, int option_) { - int optval = 0; - size_t optvallen = sizeof (int); - if (zmq_ctx_get_ext (ctx_, option_, &optval, &optvallen) == 0) { - return optval; + if (!ctx_ || !(static_cast (ctx_))->check_tag ()) { + errno = EFAULT; + return -1; } - - errno = EFAULT; - return -1; + return (static_cast (ctx_))->get (option_); } int zmq_ctx_get_ext (void *ctx_, int option_, void *optval_, size_t *optvallen_) diff --git a/tests/test_ctx_options.cpp b/tests/test_ctx_options.cpp index a1f2d00b..a7856068 100644 --- a/tests/test_ctx_options.cpp +++ b/tests/test_ctx_options.cpp @@ -283,6 +283,14 @@ void test_ctx_option_blocky () test_context_socket_close (router); } +void test_ctx_option_invalid () +{ + TEST_ASSERT_EQUAL_INT (-1, zmq_ctx_set (get_test_context (), -1, 0)); + TEST_ASSERT_EQUAL_INT (EINVAL, errno); + TEST_ASSERT_EQUAL_INT (-1, zmq_ctx_get (get_test_context (), -1)); + TEST_ASSERT_EQUAL_INT (EINVAL, errno); +} + int main (void) { setup_test_environment (); @@ -297,5 +305,6 @@ int main (void) RUN_TEST (test_ctx_thread_opts); RUN_TEST (test_ctx_zero_copy); RUN_TEST (test_ctx_option_blocky); + RUN_TEST (test_ctx_option_invalid); return UNITY_END (); }