]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
wall: check sysconf() returnvalue
authorKarel Zak <kzak@redhat.com>
Thu, 2 May 2024 08:07:04 +0000 (10:07 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 2 May 2024 08:56:26 +0000 (10:56 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/wall.c

index 4937bdc803d7577c88f2d8d4a2d27f61aaeeb28f..125fde4383ab5b30c1cf13fd3f7172f7db922e29 100644 (file)
@@ -136,10 +136,17 @@ static gid_t get_group_gid(const char *group)
 
 static struct group_workspace *init_group_workspace(const char *group)
 {
-       struct group_workspace *buf = xmalloc(sizeof(struct group_workspace));
+       struct group_workspace *buf;
+       long n;
+
+       n = sysconf(_SC_NGROUPS_MAX);
+       if (n < 0 || n > INT_MAX - 1)
+               return NULL;
+
+       buf = xmalloc(sizeof(struct group_workspace));
+       buf->ngroups = n + 1;   /* room for the primary gid */
 
        buf->requested_group = get_group_gid(group);
-       buf->ngroups = sysconf(_SC_NGROUPS_MAX) + 1;  /* room for the primary gid */
        buf->groups = xcalloc(buf->ngroups, sizeof(*buf->groups));
 
        return buf;