Unverified Commit 9861d16c authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #3285 from bjovke/my_work

Problem: Use of pipe_t after free in zmq::socket_base_t::term_endpoint(). Issue #3245.
parents 3863c869 f5d1d5d1
...@@ -553,3 +553,13 @@ void zmq::pipe_t::send_hwms_to_peer (int inhwm_, int outhwm_) ...@@ -553,3 +553,13 @@ void zmq::pipe_t::send_hwms_to_peer (int inhwm_, int outhwm_)
{ {
send_pipe_hwm (_peer, inhwm_, outhwm_); send_pipe_hwm (_peer, inhwm_, outhwm_);
} }
void zmq::pipe_t::set_endpoint_uri (const char *name_)
{
_endpoint_uri = name_;
}
std::string &zmq::pipe_t::get_endpoint_uri ()
{
return _endpoint_uri;
}
...@@ -141,6 +141,9 @@ class pipe_t : public object_t, ...@@ -141,6 +141,9 @@ class pipe_t : public object_t,
// Returns true if HWM is not reached // Returns true if HWM is not reached
bool check_hwm () const; bool check_hwm () const;
void set_endpoint_uri (const char *name_);
std::string &get_endpoint_uri ();
private: private:
// Type of the underlying lock-free pipe. // Type of the underlying lock-free pipe.
typedef ypipe_base_t<msg_t> upipe_t; typedef ypipe_base_t<msg_t> upipe_t;
...@@ -244,6 +247,10 @@ class pipe_t : public object_t, ...@@ -244,6 +247,10 @@ class pipe_t : public object_t,
const bool _conflate; const bool _conflate;
// If the pipe belongs to socket's endpoint the endpoint's name is stored here.
// Otherwise this is empty.
std::string _endpoint_uri;
// Disable copying. // Disable copying.
pipe_t (const pipe_t &); pipe_t (const pipe_t &);
const pipe_t &operator= (const pipe_t &); const pipe_t &operator= (const pipe_t &);
......
...@@ -1009,6 +1009,9 @@ void zmq::socket_base_t::add_endpoint (const char *endpoint_uri_, ...@@ -1009,6 +1009,9 @@ void zmq::socket_base_t::add_endpoint (const char *endpoint_uri_,
launch_child (endpoint_); launch_child (endpoint_);
_endpoints.ZMQ_MAP_INSERT_OR_EMPLACE (std::string (endpoint_uri_), _endpoints.ZMQ_MAP_INSERT_OR_EMPLACE (std::string (endpoint_uri_),
endpoint_pipe_t (endpoint_, pipe_)); endpoint_pipe_t (endpoint_, pipe_));
if (pipe_ != NULL)
pipe_->set_endpoint_uri (endpoint_uri_);
} }
int zmq::socket_base_t::term_endpoint (const char *endpoint_uri_) int zmq::socket_base_t::term_endpoint (const char *endpoint_uri_)
...@@ -1543,6 +1546,20 @@ void zmq::socket_base_t::pipe_terminated (pipe_t *pipe_) ...@@ -1543,6 +1546,20 @@ void zmq::socket_base_t::pipe_terminated (pipe_t *pipe_)
// Remove the pipe from the list of attached pipes and confirm its // Remove the pipe from the list of attached pipes and confirm its
// termination if we are already shutting down. // termination if we are already shutting down.
_pipes.erase (pipe_); _pipes.erase (pipe_);
// Remove the pipe from _endpoints (set it to NULL).
if (!pipe_->get_endpoint_uri ().empty ()) {
std::pair<endpoints_t::iterator, endpoints_t::iterator> range;
range = _endpoints.equal_range (pipe_->get_endpoint_uri ());
for (endpoints_t::iterator it = range.first; it != range.second; ++it) {
if (it->second.second == pipe_) {
it->second.second = NULL;
break;
}
}
}
if (is_terminating ()) if (is_terminating ())
unregister_term_ack (); unregister_term_ack ();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment