summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Hintjens <ph@imatix.com>2010-08-08 11:43:32 +0200
committerPieter Hintjens <ph@imatix.com>2010-08-08 11:43:32 +0200
commitb6cdd369e328ceca2c46758d92ad8ea6a1f59cd7 (patch)
treedd15d3f9d4b326a7816cb590551fa734e57a4f63
parent677b3d906acc97c26855bdc31126492878ad6292 (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
-rw-r--r--doc/zmq_bind.txt2
-rw-r--r--doc/zmq_close.txt3
-rw-r--r--doc/zmq_connect.txt2
-rw-r--r--doc/zmq_device.txt13
-rw-r--r--doc/zmq_getsockopt.txt2
-rw-r--r--doc/zmq_poll.txt2
-rw-r--r--doc/zmq_recv.txt2
-rw-r--r--doc/zmq_send.txt2
-rw-r--r--doc/zmq_setsockopt.txt2
-rw-r--r--doc/zmq_socket.txt3
-rw-r--r--doc/zmq_term.txt3
-rw-r--r--src/zmq.cpp63
12 files changed, 79 insertions, 20 deletions
diff --git a/doc/zmq_bind.txt b/doc/zmq_bind.txt
index 2678ca6..5eb1bcf 100644
--- a/doc/zmq_bind.txt
+++ b/doc/zmq_bind.txt
@@ -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
diff --git a/doc/zmq_close.txt b/doc/zmq_close.txt
index a1f835e..7936fca 100644
--- a/doc/zmq_close.txt
+++ b/doc/zmq_close.txt
@@ -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
diff --git a/doc/zmq_connect.txt b/doc/zmq_connect.txt
index 6121493..5634bbf 100644
--- a/doc/zmq_connect.txt
+++ b/doc/zmq_connect.txt
@@ -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
diff --git a/doc/zmq_device.txt b/doc/zmq_device.txt
index 45d4052..d5d7a18 100644
--- a/doc/zmq_device.txt
+++ b/doc/zmq_device.txt
@@ -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
diff --git a/doc/zmq_getsockopt.txt b/doc/zmq_getsockopt.txt
index 3f131ba..0a2d51e 100644
--- a/doc/zmq_getsockopt.txt
+++ b/doc/zmq_getsockopt.txt
@@ -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
diff --git a/doc/zmq_poll.txt b/doc/zmq_poll.txt
index 9761881..2648ad7 100644
--- a/doc/zmq_poll.txt
+++ b/doc/zmq_poll.txt
@@ -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
diff --git a/doc/zmq_recv.txt b/doc/zmq_recv.txt
index 8aba42a..5a7ec1b 100644
--- a/doc/zmq_recv.txt
+++ b/doc/zmq_recv.txt
@@ -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
diff --git a/doc/zmq_send.txt b/doc/zmq_send.txt
index 37524c8..ace4a66 100644
--- a/doc/zmq_send.txt
+++ b/doc/zmq_send.txt
@@ -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
diff --git a/doc/zmq_setsockopt.txt b/doc/zmq_setsockopt.txt
index c612247..0106f8f 100644
--- a/doc/zmq_setsockopt.txt
+++ b/doc/zmq_setsockopt.txt
@@ -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
diff --git a/doc/zmq_socket.txt b/doc/zmq_socket.txt
index 7f0ac4e..7d78366 100644
--- a/doc/zmq_socket.txt
+++ b/doc/zmq_socket.txt
@@ -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
diff --git a/doc/zmq_term.txt b/doc/zmq_term.txt
index 546c7a6..10455dd 100644
--- a/doc/zmq_term.txt
+++ b/doc/zmq_term.txt
@@ -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
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);
}