If sudo_getgrouplist2() returns -1, clamp ngroups based on max_groups.
The ngroups parameter is an out parameter that is filled in with the actual number of groups, which may be less than the static number allocated when max_groups is set in sudo.conf. Fixes a potential out of bounds read found by LLVM libFuzzer.
This commit is contained in:
@@ -396,9 +396,11 @@ fill_group_list(const char *user, struct sudo_cred *cred)
|
||||
if (cred->ngroups > 0) {
|
||||
cred->groups = reallocarray(NULL, cred->ngroups, sizeof(GETGROUPS_T));
|
||||
if (cred->groups != NULL) {
|
||||
/* No error on insufficient space if user specified max_groups. */
|
||||
(void)sudo_getgrouplist2(user, cred->gid,
|
||||
&cred->groups, &cred->ngroups);
|
||||
/* Clamp to max_groups if insufficient space for all groups. */
|
||||
if (sudo_getgrouplist2(user, cred->gid, &cred->groups,
|
||||
&cred->ngroups) == -1) {
|
||||
cred->ngroups = sudo_conf_max_groups();
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user