]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
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 29bd85f1e05e22d11025d4dcd4d5ca19784f0a1b..d2e00f2f647e534cf630b42913e21907f6317710 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 df18a2a83c48b5a2c3a8818d4d548c4627f9405b..0de29c22350c86b0230174a493aaa135af8c47d6 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));
 }