diff options
| author | Olivier Certner <olce@FreeBSD.org> | 2025-08-29 08:26:59 +0000 |
|---|---|---|
| committer | Olivier Certner <olce@FreeBSD.org> | 2025-09-17 12:16:05 +0000 |
| commit | 10b789d7e14862c77f77f07e8af84d73d73012c6 (patch) | |
| tree | f2d6ea27d0186f9a2200a0a1176ad368b8b8a3e7 | |
| parent | b1326edddb302a28fc9418ab60df6210513cc07c (diff) | |
linux: getsockopt(): Simplify exporting groups a bit
No functional change (intended).
Go through conversion to a 'l_gid_t' before copying out in order to cope
with differing group types (except for not representable values, of
course). This is what is done, e.g., for getgroups() in 'linux_misc.c'.
As Linux's group type is the same as ours on all architectures, we could
as well just stop bothering and copy out our memory representation,
eliminating the loop here. Whatever the choice, though, it has to be
consistent here and there.
Introduce 'out' of type 'l_gid_t' to avoid performing "by hand" array
arithmetics when copying out.
MFC after: 5 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D52280
| -rw-r--r-- | sys/compat/linux/linux_socket.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c index 539d153431c4..0e07b0a60ced 100644 --- a/sys/compat/linux/linux_socket.c +++ b/sys/compat/linux/linux_socket.c @@ -2179,6 +2179,7 @@ static int linux_getsockopt_so_peergroups(struct thread *td, struct linux_getsockopt_args *args) { + l_gid_t *out = PTRIN(args->optval); struct xucred xu; socklen_t xulen, len; int error, i; @@ -2197,13 +2198,12 @@ linux_getsockopt_so_peergroups(struct thread *td, return (error); } - /* - * "- 1" to skip the primary group. - */ + /* "- 1" to skip the primary group. */ for (i = 0; i < xu.cr_ngroups - 1; i++) { - error = copyout(xu.cr_groups + i + 1, - (void *)(args->optval + i * sizeof(l_gid_t)), - sizeof(l_gid_t)); + /* Copy to cope with a possible type discrepancy. */ + const l_gid_t g = xu.cr_groups[i + 1]; + + error = copyout(&g, out + i, sizeof(l_gid_t)); if (error != 0) return (error); } |
