socket-util: include trailing NUL byte in SOCKADDR_UN_LEN() count for fs sockets
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Oct 2018 16:26:31 +0000 (18:26 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 15 Oct 2018 17:40:51 +0000 (19:40 +0200)
This is what unix(7) recommends, hence do so.

src/basic/socket-util.h
src/test/test-socket-util.c

index 29bd85f..d2e00f2 100644 (file)
@@ -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);
index df18a2a..0de29c2 100644 (file)
@@ -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));
 }