Commit b6cdd369 authored by Pieter Hintjens's avatar Pieter Hintjens

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
parent 677b3d90
......@@ -61,6 +61,8 @@ The requested 'address' was not local.
The requested 'address' specifies a nonexistent interface.
*ETERM*::
The 0MQ 'context' associated with the specified 'socket' was terminated.
*EFAULT*::
The provided 'socket' was not valid (NULL).
EXAMPLE
......
......@@ -31,7 +31,8 @@ return `-1` and set 'errno' to one of the values defined below.
ERRORS
------
No errors are defined.
*EFAULT*::
The provided 'socket' was not valid (NULL).
SEE ALSO
......
......@@ -59,6 +59,8 @@ The requested 'transport' protocol is not supported.
The requested 'transport' protocol is not compatible with the socket type.
*ETERM*::
The 0MQ 'context' associated with the specified 'socket' was terminated.
*EFAULT*::
The provided 'socket' was not valid (NULL).
EXAMPLE
......
......@@ -89,8 +89,17 @@ Refer to linkzmq:zmq_socket[3] for a description of these socket types.
RETURN VALUE
------------
The _zmq_device()_ function always returns `-1` and 'errno' set to *ETERM* (the
0MQ 'context' associated with either of the specified sockets was terminated).
The _zmq_device()_ function shall not return if successful. Otherwise it shall
return `-1` and set 'errno' to one of the values defined below.
ERRORS
------
*ETERM*::
The 0MQ 'context' associated with the specified 'frontend' or 'backend' was
terminated.
*EFAULT*::
The provided 'frontend' or 'backend' was not valid (NULL).
EXAMPLE
......
......@@ -214,6 +214,8 @@ _option_value_, as specified by _option_len_, is insufficient for storing the
option value.
*ETERM*::
The 0MQ 'context' associated with the specified 'socket' was terminated.
*EFAULT*::
The provided 'socket' was not valid (NULL).
EXAMPLE
......
......@@ -96,6 +96,8 @@ to a different application thread.
*ETERM*::
At least one of the members of the 'items' array refers to a 'socket' whose
associated 0MQ 'context' was terminated.
*EFAULT*::
The provided 'items' was not valid (NULL).
EXAMPLE
......
......@@ -63,6 +63,8 @@ socket types that switch between several states, such as ZMQ_REP. See the
_messaging patterns_ section of linkzmq:zmq_socket[3] for more information.
*ETERM*::
The 0MQ 'context' associated with the specified 'socket' was terminated.
*EFAULT*::
The provided 'socket' was not valid (NULL).
EXAMPLE
......
......@@ -69,6 +69,8 @@ socket types that switch between several states, such as ZMQ_REP. See the
_messaging patterns_ section of linkzmq:zmq_socket[3] for more information.
*ETERM*::
The 0MQ 'context' associated with the specified 'socket' was terminated.
*EFAULT*::
The provided 'context' was not valid (NULL).
EXAMPLE
......
......@@ -229,6 +229,8 @@ The requested option _option_name_ is unknown, or the requested _option_len_ or
_option_value_ is invalid.
*ETERM*::
The 0MQ 'context' associated with the specified 'socket' was terminated.
*EFAULT*::
The provided 'socket' was not valid (NULL).
EXAMPLE
......
......@@ -242,9 +242,10 @@ ERRORS
------
*EINVAL*::
The requested socket 'type' is invalid.
*EMTHREAD*::
The maximum number of sockets within this 'context' has been exceeded.
*EFAULT*::
The provided 'context' was not valid (NULL).
SEE ALSO
......
......@@ -43,7 +43,8 @@ return `-1` and set 'errno' to one of the values defined below.
ERRORS
------
No errors are defined.
*EFAULT*::
The provided 'context' was not valid (NULL).
SEE ALSO
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment