mailing list of musl libc
 help / color / mirror / code / Atom feed
d713897680fa560def6802454d38c653f3844f0f blob 836 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
#define _GNU_SOURCE
#include <grp.h>
#include <limits.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>

#undef NGROUPS_MAX
#define NGROUPS_MAX 2

int initgroups(const char *user, gid_t gid)
{
	gid_t buf[NGROUPS_MAX], *groups = buf;
	int count = NGROUPS_MAX, prev_count = count;
	while (getgrouplist(user, gid, groups, &count) < 0) {
		if (groups != buf) free(groups);

		/* Return if failure isn't buffer size */
		if (count <= prev_count)
			return -1;

		/* Always increase by at least 50% to limit to
		 * logarithmically many retries on TOCTOU races. */
		if (count < prev_count + (prev_count>>1))
			count = prev_count + (prev_count>>1);

		groups = calloc(count, sizeof *groups);
		if (!groups) return -1;
		prev_count = count;
	}
	int ret = setgroups(count, groups);
	if (groups != buf) free(groups);
	return ret;
}
debug log:

solving d7138976 ...
found d7138976 in https://inbox.vuxu.org/musl/20240411015140.GZ4163@brightrain.aerifal.cx/
found 922a9581 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 922a958142b0ad7b1f331f30725ecec29b91a309	src/misc/initgroups.c

applying [1/1] https://inbox.vuxu.org/musl/20240411015140.GZ4163@brightrain.aerifal.cx/
diff --git a/src/misc/initgroups.c b/src/misc/initgroups.c
index 922a9581..d7138976 100644

Checking patch src/misc/initgroups.c...
Applied patch src/misc/initgroups.c cleanly.

index at:
100644 d713897680fa560def6802454d38c653f3844f0f	src/misc/initgroups.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).