mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-14 17:58:01 +08:00
Fix detection of abstract ipc pathname and length calculation.
Abstract socket pathnames must have a NULL character in the first position, but the second character must also be checked to differentiate an abstract name from the empty string. The address length must also indicate the length of the pathname because the kernel uses the entire address as the name, including NULL characters. ZMQ uses NULL-terminated strings for the address, so the abstract address length is the length of the string following the initial NULL byte plus 3; two bytes for the address family and one for the initial NULL character.
This commit is contained in:
parent
ae7fad48a8
commit
e0f4d603c2
@ -51,11 +51,18 @@ int zmq::ipc_address_t::resolve (const char *path_)
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
#if defined ZMQ_HAVE_LINUX
|
||||
if (path_[0] == '@' && !path_[1]) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
address.sun_family = AF_UNIX;
|
||||
strcpy (address.sun_path, path_);
|
||||
#if defined ZMQ_HAVE_LINUX
|
||||
if (*path_ == '@')
|
||||
/* Abstract sockets on Linux start with '\0' */
|
||||
if (path_[0] == '@')
|
||||
*address.sun_path = '\0';
|
||||
#endif
|
||||
return 0;
|
||||
@ -73,10 +80,10 @@ int zmq::ipc_address_t::to_string (std::string &addr_)
|
||||
s << "ipc://" << address.sun_path;
|
||||
#else
|
||||
s << "ipc://";
|
||||
if (*address.sun_path)
|
||||
s << address.sun_path;
|
||||
else
|
||||
if (!address.sun_path[0] && address.sun_path[1])
|
||||
s << "@" << address.sun_path + 1;
|
||||
else
|
||||
s << address.sun_path;
|
||||
#endif
|
||||
addr_ = s.str ();
|
||||
return 0;
|
||||
@ -89,6 +96,10 @@ const sockaddr *zmq::ipc_address_t::addr () const
|
||||
|
||||
socklen_t zmq::ipc_address_t::addrlen () const
|
||||
{
|
||||
#if defined ZMQ_HAVE_LINUX
|
||||
if (!address.sun_path[0] && address.sun_path[1])
|
||||
return (socklen_t) strlen(address.sun_path + 1) + sizeof (sa_family_t) + 1;
|
||||
#endif
|
||||
return (socklen_t) sizeof (address);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user