diff options
-rw-r--r-- | libpwdgrp/pwd_grp.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index b44ada432..10debbcdb 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c | |||
@@ -191,6 +191,9 @@ static char *parse_common(FILE *fp, struct passdb *db, | |||
191 | char *buf; | 191 | char *buf; |
192 | 192 | ||
193 | while ((buf = xmalloc_fgetline(fp)) != NULL) { | 193 | while ((buf = xmalloc_fgetline(fp)) != NULL) { |
194 | int n; | ||
195 | char *field; | ||
196 | |||
194 | /* Skip empty lines, comment lines */ | 197 | /* Skip empty lines, comment lines */ |
195 | if (buf[0] == '\0' || buf[0] == '#') | 198 | if (buf[0] == '\0' || buf[0] == '#') |
196 | goto free_and_next; | 199 | goto free_and_next; |
@@ -204,7 +207,16 @@ static char *parse_common(FILE *fp, struct passdb *db, | |||
204 | /* no key specified: sequential read, return a record */ | 207 | /* no key specified: sequential read, return a record */ |
205 | break; | 208 | break; |
206 | } | 209 | } |
207 | if (strcmp(key, nth_string(buf, field_pos)) == 0) { | 210 | /* Can't use nth_string() here, it does not allow empty strings |
211 | * ("\0\0" terminates the list), and a valid passwd entry | ||
212 | * "user::UID:GID..." would be mishandled */ | ||
213 | n = field_pos; | ||
214 | field = buf; | ||
215 | while (n) { | ||
216 | n--; | ||
217 | field += strlen(field) + 1; | ||
218 | } | ||
219 | if (strcmp(key, field) == 0) { | ||
208 | /* record found */ | 220 | /* record found */ |
209 | break; | 221 | break; |
210 | } | 222 | } |