From e81eb5b00af84bba991aaa6ec8e5d48ec95a38db Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 25 Nov 2012 09:23:17 -0500 Subject: [PATCH] Ignore bad lines in passwd/group file instead if stopping processing when we hit one. --- plugins/sudoers/tsgetgrpw.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/sudoers/tsgetgrpw.c b/plugins/sudoers/tsgetgrpw.c index 7b9ad790e..4fd933602 100644 --- a/plugins/sudoers/tsgetgrpw.c +++ b/plugins/sudoers/tsgetgrpw.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 2005, 2008, 2010-2011 Todd C. Miller + * Copyright (c) 2005, 2008, 2010-2012 + * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -116,32 +117,33 @@ getpwent(void) size_t len; char *cp, *colon; +next_entry: if ((colon = fgets(pwbuf, sizeof(pwbuf), pwf)) == NULL) return NULL; zero_bytes(&pw, sizeof(pw)); if ((colon = strchr(cp = colon, ':')) == NULL) - return NULL; + goto next_entry; *colon++ = '\0'; pw.pw_name = cp; if ((colon = strchr(cp = colon, ':')) == NULL) - return NULL; + goto next_entry; *colon++ = '\0'; pw.pw_passwd = cp; if ((colon = strchr(cp = colon, ':')) == NULL) - return NULL; + goto next_entry; *colon++ = '\0'; pw.pw_uid = atoi(cp); if ((colon = strchr(cp = colon, ':')) == NULL) - return NULL; + goto next_entry; *colon++ = '\0'; pw.pw_gid = atoi(cp); if ((colon = strchr(cp = colon, ':')) == NULL) - return NULL; + goto next_entry; *colon++ = '\0'; pw.pw_gecos = cp; if ((colon = strchr(cp = colon, ':')) == NULL) - return NULL; + goto next_entry; *colon++ = '\0'; pw.pw_dir = cp; pw.pw_shell = colon; @@ -237,20 +239,21 @@ getgrent(void) char *cp, *colon; int n; +next_entry: if ((colon = fgets(grbuf, sizeof(grbuf), grf)) == NULL) return NULL; zero_bytes(&gr, 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); len = strlen(colon); -- 2.40.0