2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 22:35:15 +00:00

stream-unix: only use path-based socket names

FreeBSD returns a socklen of sockaddr_storage when doing an accept on an unix
STREAM socket. The current code will assume it means a sun_path larger than 0.

That breaks some tests like the one below which don't expect to find "unix::" on
the logs.

As a Linux abstract address would not have a more useful name either, it's
better to check that sun_path starts with a non-zero byte and return 0 length in
case it doesn't.

402: ovs-ofctl replace-flows with --bundle      FAILED (ovs-ofctl.at:2928)
2016-07-08T12:44:30.068Z|00020|vconn|DBG|unix:: sent (Success): OFPT_HELLO (OF1.6) (xid=0x1):

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
Thadeu Lima de Souza Cascardo
2016-07-19 17:05:51 -03:00
committed by Ben Pfaff
parent 70c7cfef18
commit dd23522f68
3 changed files with 6 additions and 4 deletions

View File

@@ -387,9 +387,10 @@ error:
}
int
get_unix_name_len(socklen_t sun_len)
get_unix_name_len(const struct sockaddr_un *sun, socklen_t sun_len)
{
return (sun_len >= offsetof(struct sockaddr_un, sun_path)
return (sun_len >= offsetof(struct sockaddr_un, sun_path) &&
sun->sun_path[0] != 0
? sun_len - offsetof(struct sockaddr_un, sun_path)
: 0);
}

View File

@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <stdbool.h>
#include "openvswitch/types.h"
@@ -84,7 +85,7 @@ int drain_rcvbuf(int fd);
int make_unix_socket(int style, bool nonblock,
const char *bind_path, const char *connect_path);
int get_unix_name_len(socklen_t sun_len);
int get_unix_name_len(const struct sockaddr_un *sun, socklen_t sun_len);
/* Helpers for calling ioctl() on an AF_INET socket. */
struct ifreq;

View File

@@ -110,7 +110,7 @@ punix_accept(int fd, const struct sockaddr_storage *ss, size_t ss_len,
struct stream **streamp)
{
const struct sockaddr_un *sun = (const struct sockaddr_un *) ss;
int name_len = get_unix_name_len(ss_len);
int name_len = get_unix_name_len(sun, ss_len);
char name[128];
if (name_len > 0) {