From 20c125297ff59e58ed6dfcac1a525a00bed0f6bf Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 20 May 2010 17:10:16 -0400 Subject: [PATCH] Avoid possible malloc(0) if plugin returns an empty groups list. --- src/sudo.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/sudo.c b/src/sudo.c index 39ee3408c..d9a0d0730 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -494,19 +494,22 @@ command_info_to_details(char * const info[], struct command_details *details) break; cp++; } - details->groups = emalloc2(details->ngroups, sizeof(GETGROUPS_T)); - cp = info[i] + sizeof("runas_groups=") - 1; - for (j = 0; j < details->ngroups;) { - errno = 0; - ulval = strtoul(cp, &ep, 0); - if (*cp == '\0' || (*ep != ',' && *ep != '\0') || - (ulval == ULONG_MAX && errno == ERANGE)) { - break; + if (details->ngroups != 0) { + details->groups = + emalloc2(details->ngroups, sizeof(GETGROUPS_T)); + cp = info[i] + sizeof("runas_groups=") - 1; + for (j = 0; j < details->ngroups;) { + errno = 0; + ulval = strtoul(cp, &ep, 0); + 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; - cp = ep + 1; + details->ngroups = j; } - details->ngroups = j; break; } if (strncmp("runas_uid=", info[i], sizeof("runas_uid=") - 1) == 0) { -- 2.40.0