fix: websocket url without path

websocket urls without a path caused crash!
This commit is contained in:
Matthias Loy 2020-01-18 20:33:37 +01:00
parent 7ea72e5692
commit c357c378d8
2 changed files with 17 additions and 8 deletions

View File

@ -99,14 +99,17 @@ int zmq::ws_address_t::resolve (const char *name_, bool local_, bool ipv6_)
}
_host = std::string (name_, delim - name_);
// find the path part, which is optional
// find the path part, which is optional
delim = strrchr (name_, '/');
if (delim)
std::string host_name;
if (delim) {
_path = std::string (delim);
else
// remove the path, otherwise resolving the port will fail with wildcard
host_name = std::string (name_, delim - name_);
} else {
_path = std::string ("/");
// remove the path, otherwise resolving the port will fail with wildcard
std::string host_port = std::string (name_, delim - name_);
host_name = name_;
}
ip_resolver_options_t resolver_opts;
resolver_opts.bindable (local_)
@ -118,7 +121,7 @@ int zmq::ws_address_t::resolve (const char *name_, bool local_, bool ipv6_)
ip_resolver_t resolver (resolver_opts);
return resolver.resolve (&_address, host_port.c_str ());
return resolver.resolve (&_address, host_name.c_str ());
}
int zmq::ws_address_t::to_string (std::string &addr_) const

View File

@ -212,8 +212,14 @@ int zmq::ws_listener_t::set_local_address (const char *addr_)
// remove the path, otherwise resolving the port will fail with wildcard
const char *delim = strrchr (addr_, '/');
std::string host_port = std::string (addr_, delim - addr_);
if (create_socket (host_port.c_str ()) == -1)
std::string host_address;
if (delim) {
host_address = std::string (addr_, delim - addr_);
} else {
host_address = addr_;
}
if (create_socket (host_address.c_str ()) == -1)
return -1;
}