summaryrefslogtreecommitdiff
path: root/src/zmq.cpp
diff options
context:
space:
mode:
authorMartin Lucina <mato@kotelna.sk>2011-05-09 11:20:08 +0200
committerMartin Lucina <martin@lucina.net>2012-01-23 08:53:47 +0100
commitf34d1599a651dd0b8feba2397f87629733988384 (patch)
tree07694c4ed96bf7b0ecadebc76d6da3f6c0125219 /src/zmq.cpp
parent8eea9178e40abf16c0e469465a58fba3beaaf754 (diff)
parentcbaa7cfa93893876e4fd8794b6ea39f4d245b6b5 (diff)
Imported Debian patch 2.1.6-1debian/2.1.6-1
Diffstat (limited to 'src/zmq.cpp')
-rw-r--r--src/zmq.cpp40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/zmq.cpp b/src/zmq.cpp
index 929e51c..61f942d 100644
--- a/src/zmq.cpp
+++ b/src/zmq.cpp
@@ -81,7 +81,7 @@ const char *zmq_strerror (int errnum_)
int zmq_msg_init (zmq_msg_t *msg_)
{
msg_->content = (zmq::msg_content_t*) ZMQ_VSM;
- msg_->flags = 0;
+ msg_->flags = (unsigned char) ~ZMQ_MSG_MASK;
msg_->vsm_size = 0;
return 0;
}
@@ -90,7 +90,7 @@ int zmq_msg_init_size (zmq_msg_t *msg_, size_t size_)
{
if (size_ <= ZMQ_MAX_VSM_SIZE) {
msg_->content = (zmq::msg_content_t*) ZMQ_VSM;
- msg_->flags = 0;
+ msg_->flags = (unsigned char) ~ZMQ_MSG_MASK;
msg_->vsm_size = (uint8_t) size_;
}
else {
@@ -100,8 +100,8 @@ int zmq_msg_init_size (zmq_msg_t *msg_, size_t size_)
errno = ENOMEM;
return -1;
}
- msg_->flags = 0;
-
+ msg_->flags = (unsigned char) ~ZMQ_MSG_MASK;
+
zmq::msg_content_t *content = (zmq::msg_content_t*) msg_->content;
content->data = (void*) (content + 1);
content->size = size_;
@@ -117,7 +117,7 @@ int zmq_msg_init_data (zmq_msg_t *msg_, void *data_, size_t size_,
{
msg_->content = (zmq::msg_content_t*) malloc (sizeof (zmq::msg_content_t));
alloc_assert (msg_->content);
- msg_->flags = 0;
+ msg_->flags = (unsigned char) ~ZMQ_MSG_MASK;
zmq::msg_content_t *content = (zmq::msg_content_t*) msg_->content;
content->data = data_;
content->size = size_;
@@ -129,6 +129,12 @@ int zmq_msg_init_data (zmq_msg_t *msg_, void *data_, size_t size_,
int zmq_msg_close (zmq_msg_t *msg_)
{
+ // Check the validity tag.
+ if (unlikely (msg_->flags | ZMQ_MSG_MASK) != 0xff) {
+ errno = EFAULT;
+ return -1;
+ }
+
// For VSMs and delimiters there are no resources to free.
if (msg_->content != (zmq::msg_content_t*) ZMQ_DELIMITER &&
msg_->content != (zmq::msg_content_t*) ZMQ_VSM) {
@@ -148,17 +154,22 @@ int zmq_msg_close (zmq_msg_t *msg_)
}
}
- // As a safety measure, let's make the deallocated message look like
- // an empty message.
- msg_->content = (zmq::msg_content_t*) ZMQ_VSM;
+ // Remove the validity tag from the message.
msg_->flags = 0;
- msg_->vsm_size = 0;
return 0;
}
int zmq_msg_move (zmq_msg_t *dest_, zmq_msg_t *src_)
{
+#if 0
+ // Check the validity tags.
+ if (unlikely ((dest_->flags | ZMQ_MSG_MASK) != 0xff ||
+ (src_->flags | ZMQ_MSG_MASK) != 0xff)) {
+ errno = EFAULT;
+ return -1;
+ }
+#endif
zmq_msg_close (dest_);
*dest_ = *src_;
zmq_msg_init (src_);
@@ -167,6 +178,13 @@ int zmq_msg_move (zmq_msg_t *dest_, zmq_msg_t *src_)
int zmq_msg_copy (zmq_msg_t *dest_, zmq_msg_t *src_)
{
+ // Check the validity tags.
+ if (unlikely ((dest_->flags | ZMQ_MSG_MASK) != 0xff ||
+ (src_->flags | ZMQ_MSG_MASK) != 0xff)) {
+ errno = EFAULT;
+ return -1;
+ }
+
zmq_msg_close (dest_);
// VSMs and delimiters require no special handling.
@@ -190,6 +208,8 @@ int zmq_msg_copy (zmq_msg_t *dest_, zmq_msg_t *src_)
void *zmq_msg_data (zmq_msg_t *msg_)
{
+ zmq_assert ((msg_->flags | ZMQ_MSG_MASK) == 0xff);
+
if (msg_->content == (zmq::msg_content_t*) ZMQ_VSM)
return msg_->vsm_data;
if (msg_->content == (zmq::msg_content_t*) ZMQ_DELIMITER)
@@ -200,6 +220,8 @@ void *zmq_msg_data (zmq_msg_t *msg_)
size_t zmq_msg_size (zmq_msg_t *msg_)
{
+ zmq_assert ((msg_->flags | ZMQ_MSG_MASK) == 0xff);
+
if (msg_->content == (zmq::msg_content_t*) ZMQ_VSM)
return msg_->vsm_size;
if (msg_->content == (zmq::msg_content_t*) ZMQ_DELIMITER)