Avoid possible malloc(0) if plugin returns an empty groups list.

This commit is contained in:
Todd C. Miller
2010-05-20 17:10:16 -04:00
parent 9360e67a3d
commit 20c125297f

View File

@@ -494,19 +494,22 @@ command_info_to_details(char * const info[], struct command_details *details)
break; break;
cp++; cp++;
} }
details->groups = emalloc2(details->ngroups, sizeof(GETGROUPS_T)); if (details->ngroups != 0) {
cp = info[i] + sizeof("runas_groups=") - 1; details->groups =
for (j = 0; j < details->ngroups;) { emalloc2(details->ngroups, sizeof(GETGROUPS_T));
errno = 0; cp = info[i] + sizeof("runas_groups=") - 1;
ulval = strtoul(cp, &ep, 0); for (j = 0; j < details->ngroups;) {
if (*cp == '\0' || (*ep != ',' && *ep != '\0') || errno = 0;
(ulval == ULONG_MAX && errno == ERANGE)) { ulval = strtoul(cp, &ep, 0);
break; if (*cp == '\0' || (*ep != ',' && *ep != '\0') ||
(ulval == ULONG_MAX && errno == ERANGE)) {
break;
}
details->groups[j++] = (gid_t)ulval;
cp = ep + 1;
} }
details->groups[j++] = (gid_t)ulval; details->ngroups = j;
cp = ep + 1;
} }
details->ngroups = j;
break; break;
} }
if (strncmp("runas_uid=", info[i], sizeof("runas_uid=") - 1) == 0) { if (strncmp("runas_uid=", info[i], sizeof("runas_uid=") - 1) == 0) {