Commit 50e03b07 authored by Walid Boudebouda's avatar Walid Boudebouda Committed by Nils Goroll

fix bug in abstract sockets

with uds abstract sockets, sun_path should start with a NULL character followed
by the socket's name. The name is not considered to be NULL terminated and can
contain NULL bytes which have no special meaning. socklen is used to determine
the length of name and must be set to the length of the struct sockaddr_un up to
the last character of name, otherwise the 108 characters of sun_path will be
treated as the name of the socket, including NULL bytes.
parent 9f101cff
......@@ -127,7 +127,9 @@ uds_open(void *priv, const struct sockaddr_un *uds)
double *p;
int s, i, tmo;
struct pollfd fds[1];
socklen_t sl = sizeof(*uds);
socklen_t sl;
sl = VUS_socklen(uds);
AN(priv);
AN(uds);
......
......@@ -36,6 +36,7 @@ int VUS_resolver(const char *path, vus_resolved_f *func, void *priv,
const char **err);
int VUS_bind(const struct sockaddr_un *uds, const char **errp);
int VUS_connect(const char *path, int msec);
unsigned int VUS_socklen(const struct sockaddr_un *uds);
static inline int
VUS_is(const char *path)
......
......@@ -86,6 +86,8 @@ VUS_resolver(const char *path, vus_resolved_f *func, void *priv,
if (ret)
return (ret);
assert(uds.sun_path[1] != '\0');
if (func != NULL)
ret = func(priv, &uds);
return (ret);
......@@ -95,7 +97,9 @@ int
VUS_bind(const struct sockaddr_un *uds, const char **errp)
{
int sd, e;
socklen_t sl = sizeof(*uds);
socklen_t sl;
sl = VUS_socklen(uds);
if (errp != NULL)
*errp = NULL;
......@@ -133,13 +137,18 @@ VUS_connect(const char *path, int msec)
int s, i;
struct pollfd fds[1];
struct sockaddr_un uds;
socklen_t sl = (socklen_t) sizeof(uds);
socklen_t sl;
if (path == NULL)
return (-1);
i = sun_init(&uds, path, NULL);
if (i)
return (i);
assert(uds.sun_path[1] != '\0');
sl = VUS_socklen(&uds);
AN(sl);
s = socket(PF_UNIX, SOCK_STREAM, 0);
......@@ -182,3 +191,19 @@ VUS_connect(const char *path, int msec)
return (VTCP_connected(s));
}
socklen_t
VUS_socklen(const struct sockaddr_un *uds)
{
socklen_t sl;
char *p;
if (*uds->sun_path)
sl = sizeof(*uds);
else {
p = strchr(uds->sun_path + 1, '\0');
assert(p != NULL);
sl = p - (const char*)uds;
}
assert(sl <= sizeof(*uds));
return sl;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment