mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-13 22:50:19 +02:00
Problem: ZAP is allowed to be configured incorrectly or not to work
Solution: if inproc://zeromq.zap.01 exists, which means ZAP is enabled, abort immediately if it cannot be used (eg: out of memory) or it is configured incorrectly (eg: wrong socket type). Otherwise authentication failures will simply be ignored and unauthorised peers will be allowed to slip in.
This commit is contained in:
@@ -315,6 +315,12 @@ void zmq::session_base_t::process_plug ()
|
||||
start_connecting (false);
|
||||
}
|
||||
|
||||
// This functions can return 0 on success or -1 and errno=ECONNREFUSED if ZAP
|
||||
// is not setup (IE: inproc://zeromq.zap.01 does not exist in the same context)
|
||||
// or it aborts on any other error. In other words, either ZAP is not
|
||||
// configured or if it is configured it MUST be configured correctly and it
|
||||
// MUST work, otherwise authentication cannot be guaranteed and it would be a
|
||||
// security flaw.
|
||||
int zmq::session_base_t::zap_connect ()
|
||||
{
|
||||
zmq_assert (zap_pipe == NULL);
|
||||
@@ -324,12 +330,9 @@ int zmq::session_base_t::zap_connect ()
|
||||
errno = ECONNREFUSED;
|
||||
return -1;
|
||||
}
|
||||
if (peer.options.type != ZMQ_REP
|
||||
&& peer.options.type != ZMQ_ROUTER
|
||||
&& peer.options.type != ZMQ_SERVER) {
|
||||
errno = ECONNREFUSED;
|
||||
return -1;
|
||||
}
|
||||
zmq_assert (peer.options.type == ZMQ_REP ||
|
||||
peer.options.type == ZMQ_ROUTER ||
|
||||
peer.options.type == ZMQ_SERVER);
|
||||
|
||||
// Create a bi-directional pipe that will connect
|
||||
// session with zap socket.
|
||||
@@ -353,10 +356,9 @@ int zmq::session_base_t::zap_connect ()
|
||||
rc = id.init ();
|
||||
errno_assert (rc == 0);
|
||||
id.set_flags (msg_t::identity);
|
||||
if (zap_pipe->write (&id))
|
||||
zap_pipe->flush ();
|
||||
else
|
||||
return -1;
|
||||
bool ok = zap_pipe->write (&id);
|
||||
zmq_assert (ok);
|
||||
zap_pipe->flush ();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user