From 725f141fd7e8c74f0c664c6d4a18ff6df77771bc Mon Sep 17 00:00:00 2001 From: Ivan Pechorin Date: Wed, 26 Sep 2012 16:49:38 +0400 Subject: [PATCH] Fix LIBZMQ-211: REP socket asserting when getting malformed request REP socket demands at least an empty address stack. The server asserted on (msg_->flags () & msg_t::more) in rep.cpp:75 when receiving a malformed request without empty part. This patch makes a REP socket to discard and silently ignore such malformed requests. --- src/rep.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/rep.cpp b/src/rep.cpp index affa6ab9..8d8b3d79 100644 --- a/src/rep.cpp +++ b/src/rep.cpp @@ -72,12 +72,24 @@ int zmq::rep_t::xrecv (msg_t *msg_, int flags_) int rc = router_t::xrecv (msg_, flags_); if (rc != 0) return rc; - zmq_assert (msg_->flags () & msg_t::more); - bool bottom = (msg_->size () == 0); - rc = router_t::xsend (msg_, flags_); - errno_assert (rc == 0); - if (bottom) - break; + + if ((msg_->flags () & msg_t::more)) { + // Empty message part delimits the traceback stack. + bool bottom = (msg_->size () == 0); + + // Push it to the reply pipe. + rc = router_t::xsend (msg_, flags_); + errno_assert (rc == 0); + + if (bottom) + break; + } + else { + // If the traceback stack is malformed, discard anything + // already sent to pipe (we're at end of invalid message). + rc = router_t::rollback (); + errno_assert (rc == 0); + } } request_begins = false; }