Merge pull request #1109 from hintjens/master

Set EINVAL on invalid tcp:// endpoint in zmq_connect
This commit is contained in:
Richard Newton 2014-06-25 12:41:37 +01:00
commit 47c796276f
3 changed files with 23 additions and 41 deletions

View File

@ -189,9 +189,13 @@ int zmq::socket_base_t::parse_uri (const char *uri_,
int zmq::socket_base_t::check_protocol (const std::string &protocol_)
{
// First check out whether the protcol is something we are aware of.
if (protocol_ != "inproc" && protocol_ != "ipc" && protocol_ != "tcp" &&
protocol_ != "pgm" && protocol_ != "epgm" && protocol_ != "tipc" &&
protocol_ != "norm") {
if (protocol_ != "inproc"
&& protocol_ != "ipc"
&& protocol_ != "tcp"
&& protocol_ != "pgm"
&& protocol_ != "epgm"
&& protocol_ != "tipc"
&& protocol_ != "norm") {
errno = EPROTONOSUPPORT;
return -1;
}
@ -356,12 +360,7 @@ int zmq::socket_base_t::bind (const char *addr_)
// Parse addr_ string.
std::string protocol;
std::string address;
rc = parse_uri (addr_, protocol, address);
if (rc != 0)
return -1;
rc = check_protocol (protocol);
if (rc != 0)
if (parse_uri (addr_, protocol, address) || check_protocol (protocol))
return -1;
if (protocol == "inproc") {
@ -464,12 +463,7 @@ int zmq::socket_base_t::connect (const char *addr_)
// Parse addr_ string.
std::string protocol;
std::string address;
rc = parse_uri (addr_, protocol, address);
if (rc != 0)
return -1;
rc = check_protocol (protocol);
if (rc != 0)
if (parse_uri (addr_, protocol, address) || check_protocol (protocol))
return -1;
if (protocol == "inproc") {
@ -625,6 +619,7 @@ int zmq::socket_base_t::connect (const char *addr_)
}
}
if (rc == -1) {
errno = EINVAL;
delete paddr;
return -1;
}
@ -743,12 +738,7 @@ int zmq::socket_base_t::term_endpoint (const char *addr_)
// Parse addr_ string.
std::string protocol;
std::string address;
rc = parse_uri (addr_, protocol, address);
if (rc != 0)
return -1;
rc = check_protocol (protocol);
if (rc != 0)
if (parse_uri (addr_, protocol, address) || check_protocol (protocol))
return -1;
// Disconnect an inproc socket
@ -1222,12 +1212,7 @@ int zmq::socket_base_t::monitor (const char *addr_, int events_)
// Parse addr_ string.
std::string protocol;
std::string address;
int rc = parse_uri (addr_, protocol, address);
if (rc != 0)
return -1;
rc = check_protocol (protocol);
if (rc != 0)
if (parse_uri (addr_, protocol, address) || check_protocol (protocol))
return -1;
// Event notification only supported over inproc://
@ -1243,7 +1228,7 @@ int zmq::socket_base_t::monitor (const char *addr_, int events_)
// Never block context termination on pending event messages
int linger = 0;
rc = zmq_setsockopt (monitor_socket, ZMQ_LINGER, &linger, sizeof (linger));
int rc = zmq_setsockopt (monitor_socket, ZMQ_LINGER, &linger, sizeof (linger));
if (rc == -1)
stop_monitor ();

View File

@ -88,9 +88,7 @@ bool getenvi(const char *env_, int &result_)
{
char *str = getenv (env_);
if (str == NULL)
{
return false;
}
std::stringstream ss(str);
return ss >> result_;
@ -104,8 +102,7 @@ void zmq::thread_t::start (thread_fn *tfn_, void *arg_)
posix_assert (rc);
int prio;
if(getenvi("ZMQ_THREAD_PRIO", prio))
{
if (getenvi ("ZMQ_THREAD_PRIO", prio)) {
int policy = SCHED_RR;
getenvi ("ZMQ_THREAD_POLICY", policy);