Hi

It has been a little while since I posted the first patch for this. This patch 
applies ON TOP OF the previous patch and fixes the comments that I received on 
the earlier patch (errors I had made really). It includes support for the 
one_byte_size case and uses the logic that was agreed on for determining the 
size. 

I investigated a way to notify the sender of violating the maximum size if he 
set it himself but I think this should wait until sys://log and the like is in 
place. Conceivable you could then have a pgm broadcast stating a node's 
settings and thus give client a chance to use this as well, but that should be 
entirely up to the application.

Regards,
Mikael
From 822c0d33f8c73eec93c00f29fb27c0b7097ff85c Mon Sep 17 00:00:00 2001
From: Mikael Kjaer <m...@designtech.dk>
Date: Fri, 12 Nov 2010 21:23:08 +0100
Subject: [PATCH] Fix maximum message size option and decoder.

Signed-off-by: Mikael Kjaer <m...@designtech.dk>
---
 src/decoder.cpp      |    7 +++--
 src/decoder.hpp      |    4 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/decoder.cpp b/src/decoder.cpp
index 45fd4ef..1ee2029 100644
--- a/src/decoder.cpp
+++ b/src/decoder.cpp
@@ -54,8 +54,9 @@ bool zmq::decoder_t::one_byte_size_ready ()
         next_step (tmpbuf, 8, &decoder_t::eight_byte_size_ready);
     else {
 
+        size_t size = (size_t)*tmpbuf;
         //  There has to be at least one byte (the flags) in the message).
-        if (!*tmpbuf) {
+        if (!size || over_maximum_size(size)) {
             decoding_error ();
             return false;
         }
@@ -63,7 +64,7 @@ bool zmq::decoder_t::one_byte_size_ready ()
         //  in_progress is initialised at this point so in theory we should
         //  close it before calling zmq_msg_init_size, however, it's a 0-byte
         //  message and thus we can treat it as uninitialised...
-        int rc = zmq_msg_init_size (&in_progress, *tmpbuf - 1);
+        int rc = zmq_msg_init_size (&in_progress, size - 1);
         if (rc != 0 && errno == ENOMEM) {
             decoding_error ();
             return false;
@@ -82,7 +83,7 @@ bool zmq::decoder_t::eight_byte_size_ready ()
     size_t size = (size_t) get_uint64 (tmpbuf);
 
     //  There has to be at least one byte (the flags) in the message).
-    if (!size && !under_maximum_size(size)) {
+    if (!size || over_maximum_size(size)) {
         decoding_error ();
         return false;
     }
diff --git a/src/decoder.hpp b/src/decoder.hpp
index 6dc234e..47c4a51 100644
--- a/src/decoder.hpp
+++ b/src/decoder.hpp
@@ -159,9 +159,9 @@ namespace zmq
             next = NULL;
         }
 
-        inline bool under_maximum_size (size_t size)
+        inline bool over_maximum_size (const size_t &size)
         {
-            return (max_msgsize != 0 && size < max_msgsize);
+            return (max_msgsize != 0 && size > max_msgsize);
         }
 
     private:
-- 
1.7.0.2.msysgit.0

_______________________________________________
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to