From 1beb54cef0281a5959af64fb1d0d0e9021e52a3c Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Tue, 17 Jun 2014 16:24:56 +0200 Subject: [PATCH] Added militant API checking on zmq_getsockopt --- src/options.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/options.cpp b/src/options.cpp index 959b2a55..617231c3 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -68,6 +68,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, #if defined (ZMQ_ACT_MILITANT) bool malformed = true; // Did caller pass a bad option value? #endif + switch (option_) { case ZMQ_SNDHWM: if (is_int && value >= 0) { @@ -467,6 +468,9 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) { bool is_int = (*optvallen_ == sizeof (int)); int *value = (int *) optval_; +#if defined (ZMQ_ACT_MILITANT) + bool malformed = true; // Did caller pass a bad option value? +#endif switch (option_) { case ZMQ_SNDHWM: @@ -773,7 +777,17 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) return 0; } break; + + default: +#if defined (ZMQ_ACT_MILITANT) + malformed = false; +#endif + break; } +#if defined (ZMQ_ACT_MILITANT) + if (malformed) + zmq_assert (false); +#endif errno = EINVAL; return -1; }