summaryrefslogtreecommitdiff
path: root/src/socket_base.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/socket_base.cpp')
-rw-r--r--src/socket_base.cpp22
1 files changed, 18 insertions, 4 deletions
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_)