]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
socket-util: make sure SO_PEERSEC returned string is always NUL terminated
authorLennart Poettering <lennart@poettering.net>
Thu, 23 Nov 2023 17:05:04 +0000 (18:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 21 Dec 2023 14:21:23 +0000 (15:21 +0100)
it's not entirely clear to me if the manual NUL termination is
necessary, but let's better be safe than sorry, since this is apparently
up to the LSMs, and I am not sure we can trust them all.

A lot of other code (such as dbus-broker) patches in the NUL byte, hence
let's be rather safe-then-sorry, it's trivial after all.

src/basic/socket-util.c

index beb64d8e6c7bf2edce4e30e3d21e0277a1a5126a..47d83f3710fba728ec3397cfbe2b8e9dc0ca72ed 100644 (file)
@@ -907,8 +907,10 @@ int getpeersec(int fd, char **ret) {
                 if (!s)
                         return -ENOMEM;
 
-                if (getsockopt(fd, SOL_SOCKET, SO_PEERSEC, s, &n) >= 0)
+                if (getsockopt(fd, SOL_SOCKET, SO_PEERSEC, s, &n) >= 0) {
+                        s[n] = 0;
                         break;
+                }
 
                 if (errno != ERANGE)
                         return -errno;