sd-bus: make parsing of AF_UNIX socket addresses more strict
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Oct 2018 16:17:57 +0000 (18:17 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 15 Oct 2018 17:40:51 +0000 (19:40 +0200)
Insist on NUL termination, just to be safe rather than sorry. The kernel
doesn't require it, but it's really annoying if people rely on this,
hence refuse this early.

src/libsystemd/sd-bus/sd-bus.c

index 7868e53..d6c0095 100644 (file)
@@ -730,7 +730,7 @@ static int parse_unix_address(sd_bus *b, const char **p, char **guid) {
 
         if (path) {
                 l = strlen(path);
-                if (l > sizeof(b->sockaddr.un.sun_path))
+                if (l >= sizeof(b->sockaddr.un.sun_path)) /* We insist on NUL termination */
                         return -E2BIG;
 
                 b->sockaddr.un.sun_family = AF_UNIX;
@@ -738,7 +738,7 @@ static int parse_unix_address(sd_bus *b, const char **p, char **guid) {
                 b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + l;
         } else if (abstract) {
                 l = strlen(abstract);
-                if (l > sizeof(b->sockaddr.un.sun_path) - 1)
+                if (l >= sizeof(b->sockaddr.un.sun_path) - 1) /* We insist on NUL termination */
                         return -E2BIG;
 
                 b->sockaddr.un.sun_family = AF_UNIX;