diff options
author | Pieter Hintjens <ph@imatix.com> | 2010-08-08 11:43:32 +0200 |
---|---|---|
committer | Pieter Hintjens <ph@imatix.com> | 2010-08-08 11:43:32 +0200 |
commit | b6cdd369e328ceca2c46758d92ad8ea6a1f59cd7 (patch) | |
tree | dd15d3f9d4b326a7816cb590551fa734e57a4f63 /src | |
parent | 677b3d906acc97c26855bdc31126492878ad6292 (diff) |
Added error checking (EFAULT) for null arguments
* Fixed zmq_term, zmq_socket, zmq_close, zmq_setsockopt,
* zmq_getsockopt, zmq_bind, zmq_connect, zmq_send,
* zmq_recv, zmq_poll, zmq_device, zmq_stopwatch_stop
* Updated Reference Manual for these methods
Diffstat (limited to 'src')
-rw-r--r-- | src/zmq.cpp | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/src/zmq.cpp b/src/zmq.cpp index 32862bb..8d2fd05 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -275,7 +275,10 @@ int zmq_term (void *ctx_) int rc = ((zmq::ctx_t*) ctx_)->term (); int en = errno; - zmq_assert (ctx_); + if (!ctx_) { + errno = EFAULT; + return -1; + } #if defined ZMQ_HAVE_OPENPGM // Shut down the OpenPGM library. if (pgm_shutdown () != TRUE) @@ -288,13 +291,19 @@ int zmq_term (void *ctx_) void *zmq_socket (void *ctx_, int type_) { - zmq_assert (ctx_); + if (!ctx_) { + errno = EFAULT; + return NULL; + } return (void*) (((zmq::ctx_t*) ctx_)->create_socket (type_)); } int zmq_close (void *s_) { - zmq_assert (s_); + if (!s_) { + errno = EFAULT; + return -1; + } ((zmq::socket_base_t*) s_)->close (); return 0; } @@ -302,39 +311,57 @@ int zmq_close (void *s_) int zmq_setsockopt (void *s_, int option_, const void *optval_, size_t optvallen_) { - zmq_assert (s_); + if (!s_) { + errno = EFAULT; + return -1; + } return (((zmq::socket_base_t*) s_)->setsockopt (option_, optval_, optvallen_)); } int zmq_getsockopt (void *s_, int option_, void *optval_, size_t *optvallen_) { - zmq_assert (s_); + if (!s_) { + errno = EFAULT; + return -1; + } return (((zmq::socket_base_t*) s_)->getsockopt (option_, optval_, optvallen_)); } int zmq_bind (void *s_, const char *addr_) { - zmq_assert (s_); + if (!s_) { + errno = EFAULT; + return -1; + } return (((zmq::socket_base_t*) s_)->bind (addr_)); } int zmq_connect (void *s_, const char *addr_) { - zmq_assert (s_); + if (!s_) { + errno = EFAULT; + return -1; + } return (((zmq::socket_base_t*) s_)->connect (addr_)); } int zmq_send (void *s_, zmq_msg_t *msg_, int flags_) { - zmq_assert (s_); + if (!s_) { + errno = EFAULT; + return -1; + } return (((zmq::socket_base_t*) s_)->send (msg_, flags_)); } int zmq_recv (void *s_, zmq_msg_t *msg_, int flags_) { - zmq_assert (s_); + if (!s_) { + errno = EFAULT; + return -1; + } return (((zmq::socket_base_t*) s_)->recv (msg_, flags_)); } @@ -346,8 +373,10 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) defined ZMQ_HAVE_HPUX || defined ZMQ_HAVE_AIX ||\ defined ZMQ_HAVE_NETBSD - zmq_assert (items_); - + if (!items_) { + errno = EFAULT; + return -1; + } pollfd *pollfds = (pollfd*) malloc (nitems_ * sizeof (pollfd)); zmq_assert (pollfds); int npollfds = 0; @@ -659,9 +688,10 @@ int zmq_errno () int zmq_device (int device_, void *insocket_, void *outsocket_) { - zmq_assert (insocket_); - zmq_assert (outsocket_); - + if (!insocket_ || !outsocket_) { + errno = EFAULT; + return -1; + } switch (device_) { case ZMQ_FORWARDER: return zmq::forwarder ((zmq::socket_base_t*) insocket_, @@ -735,7 +765,10 @@ unsigned long zmq_stopwatch_stop (void *watch_) { uint64_t end = now (); uint64_t start = *(uint64_t*) watch_; - zmq_assert (watch_); + if (!watch_) { + errno = EFAULT; + return -1; + } free (watch_); return (unsigned long) (end - start); } |