sd-bus: rework how we initialize struct sockaddr_un
Let's use structured initialization, but more importantly, let's increase salen by 1, if we reference AF_UNIX sockets in the file system, so that they also contain the trailing NUL byte. This is what unix(7) suggests to do, hence follow it.
This commit is contained in:
parent
1d261418e2
commit
95cb14b068
|
@ -733,17 +733,25 @@ static int parse_unix_address(sd_bus *b, const char **p, char **guid) {
|
||||||
if (l >= sizeof(b->sockaddr.un.sun_path)) /* We insist on NUL termination */
|
if (l >= sizeof(b->sockaddr.un.sun_path)) /* We insist on NUL termination */
|
||||||
return -E2BIG;
|
return -E2BIG;
|
||||||
|
|
||||||
b->sockaddr.un.sun_family = AF_UNIX;
|
b->sockaddr.un = (struct sockaddr_un) {
|
||||||
strncpy(b->sockaddr.un.sun_path, path, sizeof(b->sockaddr.un.sun_path));
|
.sun_family = AF_UNIX,
|
||||||
b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + l;
|
};
|
||||||
} else if (abstract) {
|
|
||||||
|
memcpy(b->sockaddr.un.sun_path, path, l);
|
||||||
|
b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + l + 1;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
assert(abstract);
|
||||||
|
|
||||||
l = strlen(abstract);
|
l = strlen(abstract);
|
||||||
if (l >= sizeof(b->sockaddr.un.sun_path) - 1) /* We insist on NUL termination */
|
if (l >= sizeof(b->sockaddr.un.sun_path) - 1) /* We insist on NUL termination */
|
||||||
return -E2BIG;
|
return -E2BIG;
|
||||||
|
|
||||||
b->sockaddr.un.sun_family = AF_UNIX;
|
b->sockaddr.un = (struct sockaddr_un) {
|
||||||
b->sockaddr.un.sun_path[0] = 0;
|
.sun_family = AF_UNIX,
|
||||||
strncpy(b->sockaddr.un.sun_path+1, abstract, sizeof(b->sockaddr.un.sun_path)-1);
|
};
|
||||||
|
|
||||||
|
memcpy(b->sockaddr.un.sun_path+1, abstract, l);
|
||||||
b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + 1 + l;
|
b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + 1 + l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue