--- embedaddon/sudo/plugins/group_file/getgrent.c 2013/07/22 00:51:38 1.1.1.1 +++ embedaddon/sudo/plugins/group_file/getgrent.c 2014/06/15 16:12:54 1.1.1.2 @@ -45,6 +45,7 @@ #include #include "missing.h" +#include "sudo_util.h" #ifndef LINE_MAX # define LINE_MAX 2048 @@ -101,25 +102,31 @@ mygetgrent(void) static struct group gr; static char grbuf[LINE_MAX], *gr_mem[GRMEM_MAX+1]; size_t len; + id_t id; char *cp, *colon; + const char *errstr; int n; +next_entry: if ((colon = fgets(grbuf, sizeof(grbuf), grf)) == NULL) return NULL; memset(&gr, 0, sizeof(gr)); if ((colon = strchr(cp = colon, ':')) == NULL) - return NULL; + goto next_entry; *colon++ = '\0'; gr.gr_name = cp; if ((colon = strchr(cp = colon, ':')) == NULL) - return NULL; + goto next_entry; *colon++ = '\0'; gr.gr_passwd = cp; if ((colon = strchr(cp = colon, ':')) == NULL) - return NULL; + goto next_entry; *colon++ = '\0'; - gr.gr_gid = atoi(cp); + id = atoid(cp, NULL, NULL, &errstr); + if (errstr != NULL) + goto next_entry; + gr.gr_gid = (gid_t)id; len = strlen(colon); if (len > 0 && colon[len - 1] == '\n') colon[len - 1] = '\0';