From 71bef330fc9f09ee070c90d174fc0bcb7783b38d Mon Sep 17 00:00:00 2001 From: Dhammika Pathirana Date: Sat, 23 Oct 2010 20:59:54 +0200 Subject: handle decoding malformed messages Signed-off-by: Dhammika Pathirana --- src/decoder.hpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/decoder.hpp') diff --git a/src/decoder.hpp b/src/decoder.hpp index 87982a0..ab7d454 100644 --- a/src/decoder.hpp +++ b/src/decoder.hpp @@ -98,9 +98,13 @@ namespace zmq read_pos += size_; to_read -= size_; - while (!to_read) - if (!(static_cast (this)->*next) ()) + while (!to_read) { + if (!(static_cast (this)->*next) ()) { + if (unlikely (!(static_cast (this)->next))) + return (size_t) -1; return size_; + } + } return size_; } @@ -109,9 +113,13 @@ namespace zmq // Try to get more space in the message to fill in. // If none is available, return. - while (!to_read) - if (!(static_cast (this)->*next) ()) + while (!to_read) { + if (!(static_cast (this)->*next) ()) { + if (unlikely (!(static_cast (this)->next))) + return (size_t) -1; return pos; + } + } // If there are no more data in the buffer, return. if (pos == size_) @@ -142,6 +150,13 @@ namespace zmq next = next_; } + // This function should be called from the derived class to + // abort decoder state machine. + inline void decoding_error () + { + next = NULL; + } + private: unsigned char *read_pos; -- cgit v1.2.3