From cbaa7cfa93893876e4fd8794b6ea39f4d245b6b5 Mon Sep 17 00:00:00 2001 From: Martin Lucina Date: Mon, 23 Jan 2012 08:53:45 +0100 Subject: Imported Upstream version 2.1.6 --- src/socket_base.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/socket_base.cpp') diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 4cefb6f..4317bb0 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -87,7 +87,7 @@ zmq::socket_base_t *zmq::socket_base_t::create (int type_, class ctx_t *parent_, break; case ZMQ_XREP: s = new (std::nothrow) xrep_t (parent_, tid_); - break; + break; case ZMQ_PULL: s = new (std::nothrow) pull_t (parent_, tid_); break; @@ -99,7 +99,7 @@ zmq::socket_base_t *zmq::socket_base_t::create (int type_, class ctx_t *parent_, break; case ZMQ_XSUB: s = new (std::nothrow) xsub_t (parent_, tid_); - break; + break; default: errno = EINVAL; return NULL; @@ -334,7 +334,7 @@ int zmq::socket_base_t::bind (const char *addr_) // For convenience's sake, bind can be used interchageable with // connect for PGM and EPGM transports. - return connect (addr_); + return connect (addr_); } zmq_assert (false); @@ -458,11 +458,18 @@ int zmq::socket_base_t::connect (const char *addr_) int zmq::socket_base_t::send (::zmq_msg_t *msg_, int flags_) { + // Check whether the library haven't been shut down yet. if (unlikely (ctx_terminated)) { errno = ETERM; return -1; } + // Check whether message passed to the function is valid. + if (unlikely ((msg_->flags | ZMQ_MSG_MASK) != 0xff)) { + errno = EFAULT; + return -1; + } + // Process pending commands, if any. int rc = process_commands (false, true); if (unlikely (rc != 0)) @@ -496,11 +503,18 @@ int zmq::socket_base_t::send (::zmq_msg_t *msg_, int flags_) int zmq::socket_base_t::recv (::zmq_msg_t *msg_, int flags_) { + // Check whether the library haven't been shut down yet. if (unlikely (ctx_terminated)) { errno = ETERM; return -1; } + // Check whether message passed to the function is valid. + if (unlikely ((msg_->flags | ZMQ_MSG_MASK) != 0xff)) { + errno = EFAULT; + return -1; + } + // Get the message. int rc = xrecv (msg_, flags_); int err = errno; @@ -622,7 +636,7 @@ zmq::session_t *zmq::socket_base_t::find_session (const blob_t &name_) session->inc_seqnum (); sessions_sync.unlock (); - return session; + return session; } void zmq::socket_base_t::start_reaping (poller_t *poller_) -- cgit v1.2.3