From adbd29bfa16ae4d58c767d4b03e28841c7cd7fc5 Mon Sep 17 00:00:00 2001 From: Martin Hurton Date: Tue, 15 May 2012 12:51:54 +0200 Subject: Do not crash when multiple peers connect to PAIR socket When more then one peer connected to a PAIR socket, an application aborted due to assertion failure. This patch changes the PAIR socket behaviour so that it rejects any further connection requests. --- src/pair.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pair.cpp b/src/pair.cpp index b4cb0b4..531bfc5 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -38,14 +38,20 @@ xs::pair_t::~pair_t () void xs::pair_t::xattach_pipe (pipe_t *pipe_, bool icanhasall_) { - xs_assert (!pipe); - pipe = pipe_; + xs_assert (pipe_ != NULL); + + // XS_PAIR socket can only be connected to a single peer. + // The socket rejects any further connection requests. + if (pipe == NULL) + pipe = pipe_; + else + pipe_->terminate (false); } void xs::pair_t::xterminated (pipe_t *pipe_) { - xs_assert (pipe_ == pipe); - pipe = NULL; + if (pipe_ == pipe) + pipe = NULL; } void xs::pair_t::xread_activated (pipe_t *pipe_) -- cgit v1.2.3