Skip to content

Commit

Permalink
Use our own define instead of NGROUPS_MAX.
Browse files Browse the repository at this point in the history
musl (as of version 1.2.2) defines NGROUPS_MAX to 32, but glibc and the
kernel define it to 65536. Since musl might change the definition at
some point, and the nss_initgroups interface allows the callee to
realloc the buffer, we don't have to allocate the maximum value upfront,
and can keep using 32 as a reasonable initial default.

Closes: #20 [via git-merge-pr]
  • Loading branch information
ericonr authored and the-maldridge committed Jul 5, 2021
1 parent 548d755 commit d52fb3f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/socket_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
/* glibc's NSS_BUFLEN_PASSWD (from pwd/pwd.h) and NSS_BUFLEN_GROUP (from grp/grp.h)
* are set to 1024 and consider it a reasonable default */
#define BUF_LEN_DEFAULT 1024
/* NGROUPS_MAX value for musl as of 1.2.2, might change
* to keep up with the kernel definition, so we define our own */
#define INITGR_ALLOC 32

static int return_result(int fd, int swap, uint32_t reqtype, void *key);

Expand Down Expand Up @@ -241,7 +244,7 @@ static enum nss_status nss_getkey(uint32_t reqtype, struct mod_passwd *mod_passw
case GETINITGR:
initgroups_res = res;
initgroups_res->end = 0;
initgroups_res->alloc = NGROUPS_MAX + 1;
initgroups_res->alloc = INITGR_ALLOC + 1;
initgroups_res->grps = (gid_t*)malloc(sizeof(gid_t) * initgroups_res->alloc);
retval = mod_group->nss_initgroups_dyn((char*)key, (gid_t)-1, &(initgroups_res->end), &(initgroups_res->alloc), &(initgroups_res->grps), UINT32_MAX, ret);
break;
Expand Down

0 comments on commit d52fb3f

Please sign in to comment.