From: Lennart Poettering Date: Mon, 15 Oct 2018 16:26:31 +0000 (+0200) Subject: socket-util: include trailing NUL byte in SOCKADDR_UN_LEN() count for fs sockets X-Git-Tag: v240~538^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69995bffb7f2fb589e2191523859afd896c02220;p=thirdparty%2Fsystemd.git socket-util: include trailing NUL byte in SOCKADDR_UN_LEN() count for fs sockets This is what unix(7) recommends, hence do so. --- diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h index 29bd85f1e05..d2e00f2f647 100644 --- a/src/basic/socket-util.h +++ b/src/basic/socket-util.h @@ -184,7 +184,7 @@ struct cmsghdr* cmsg_find(struct msghdr *mh, int level, int type, socklen_t leng offsetof(struct sockaddr_un, sun_path) + \ (_sa->sun_path[0] == 0 ? \ 1 + strnlen(_sa->sun_path+1, sizeof(_sa->sun_path)-1) : \ - strnlen(_sa->sun_path, sizeof(_sa->sun_path))); \ + strnlen(_sa->sun_path, sizeof(_sa->sun_path))+1); \ }) int socket_ioctl_fd(void); diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c index df18a2a83c4..0de29c22350 100644 --- a/src/test/test-socket-util.c +++ b/src/test/test-socket-util.c @@ -405,7 +405,7 @@ static void test_sockaddr_un_len(void) { .sun_path = "\0foobar", }; - assert_se(SOCKADDR_UN_LEN(fs) == offsetof(struct sockaddr_un, sun_path) + strlen(fs.sun_path)); + assert_se(SOCKADDR_UN_LEN(fs) == offsetof(struct sockaddr_un, sun_path) + strlen(fs.sun_path) + 1); assert_se(SOCKADDR_UN_LEN(abstract) == offsetof(struct sockaddr_un, sun_path) + 1 + strlen(abstract.sun_path + 1)); }