From 1b74e5d307e7f0eb64389e0734cad08ce8b55f81 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 16 Feb 2012 10:02:31 +0900 Subject: Fixes to xs::xpub_t::xread_activated MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. If the subscription is malformed, drop it silently. 2. Fixes a memory leak Signed-off-by: Staffan Gimåker Signed-off-by: Martin Sustrik --- src/xpub.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/xpub.cpp b/src/xpub.cpp index f5520f7..bf73399 100644 --- a/src/xpub.cpp +++ b/src/xpub.cpp @@ -63,7 +63,14 @@ void xs::xpub_t::xread_activated (pipe_t *pipe_) // Apply the subscription to the trie. unsigned char *data = (unsigned char*) sub.data (); size_t size = sub.size (); - xs_assert (size > 0 && (*data == 0 || *data == 1)); + + // TODO: In the case of malformed subscription we will simply ignore + // it for now. However, we should close the connection instead. + if (size <= 0 || (*data == 0 && *data == 1)) { + sub.close (); + return; + } + bool unique; if (*data == 0) unique = subscriptions.rm (data + 1, size - 1, pipe_); @@ -76,6 +83,7 @@ void xs::xpub_t::xread_activated (pipe_t *pipe_) pending.push_back (blob_t ((unsigned char*) sub.data (), sub.size ())); } + sub.close (); } void xs::xpub_t::xwrite_activated (pipe_t *pipe_) -- cgit v1.2.3