File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,11 +70,16 @@ template <typename StreamT, typename T>
7070StreamT& print_unix_endpoint (StreamT& os, const T& ep)
7171{
7272 constexpr const char * scheme = " unix://" ;
73- // abstract unix socket's path starts with '\0' and not null-terminated
7473 const auto * path = reinterpret_cast <const sockaddr_un*>(ep.data ())->sun_path ;
7574 if (path[0 ] == ' \0 ' ) {
76- size_t size = ep.size () - sizeof (std::declval<sockaddr_un>().sun_family ) - 1 ;
77- os << scheme << ' |' << std::string_view{path + 1 , size};
75+ int size = ep.size () - sizeof (std::declval<sockaddr_un>().sun_family ) - 1 ;
76+ if (size <= 0 ) {
77+ // No path
78+ os << scheme;
79+ return os;
80+ }
81+ // abstract unix socket's path starts with '\0' and not null-terminated
82+ os << scheme << ' |' << std::string_view{path + 1 , static_cast <std::size_t >(size)};
7883 return os;
7984 }
8085 os << scheme << *ep.data ();
Original file line number Diff line number Diff line change @@ -179,6 +179,18 @@ BOOST_AUTO_TEST_CASE(ParseStreamUnixAbstractCase)
179179 BOOST_CHECK_EQUAL (to_string (ep), uri);
180180}
181181
182+ BOOST_AUTO_TEST_CASE (ParseStreamUnixEmptyCase)
183+ {
184+ auto sock = os::socket (net::UnixStreamProtocol{});
185+ StreamEndpoint ep;
186+ get_sock_name (sock.get (), ep);
187+
188+ BOOST_CHECK_EQUAL (ep.protocol ().family (), AF_UNIX);
189+ BOOST_CHECK_EQUAL (ep.protocol ().type (), SOCK_STREAM);
190+ BOOST_CHECK_EQUAL (ep.protocol ().protocol (), 0 );
191+ BOOST_CHECK_EQUAL (to_string (ep), " unix://" );
192+ }
193+
182194BOOST_AUTO_TEST_CASE (ParseStreamBindCase)
183195{
184196 const auto ep = parse_stream_endpoint (" tcp4://:80" );
You can’t perform that action at this time.
0 commit comments