ext/zeromq/src/ipc_address.cpp in rbczmq-1.7.2 vs ext/zeromq/src/ipc_address.cpp in rbczmq-1.7.3
- old
+ new
@@ -49,15 +49,22 @@
{
if (strlen (path_) >= sizeof (address.sun_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;
}
@@ -71,14 +78,14 @@
std::stringstream s;
#if !defined ZMQ_HAVE_LINUX
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;
}
@@ -87,9 +94,13 @@
return (sockaddr*) &address;
}
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);
}
#endif