]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
socket-util: check for sysconf() error before using value
authorLuca Boccassi <bluca@debian.org>
Tue, 30 Jan 2024 12:16:26 +0000 (12:16 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 30 Jan 2024 15:19:16 +0000 (15:19 +0000)
Otherwise -1 will be casted to uint32_t. Found by coverity.

CID#1533989

Follow-up for 7e8aa5c2eebd86efe9bbf36d8db1e98964611aab

src/basic/socket-util.c

index a9ad1cc9936e7d9ff0d95503d6585ff5f96a3936..68e6afc67fc162de913d66d5d668ab29288e20a4 100644 (file)
@@ -930,13 +930,15 @@ int getpeersec(int fd, char **ret) {
 }
 
 int getpeergroups(int fd, gid_t **ret) {
+        socklen_t n = sizeof(gid_t) * 64U;
         _cleanup_free_ gid_t *d = NULL;
 
         assert(fd >= 0);
         assert(ret);
 
         long ngroups_max = sysconf(_SC_NGROUPS_MAX);
-        socklen_t n = sizeof(gid_t) * MAX((socklen_t) ngroups_max, 64U);
+        if (ngroups_max > 0)
+                n = MAX(n, sizeof(gid_t) * (socklen_t) ngroups_max);
 
         for (;;) {
                 d = malloc(n);