From 129c2913052c8f3fef59a58e2b508ea0eff14d7a Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Tue, 7 Jul 2015 21:05:20 +0000 Subject: pw: fail if an invalid entry is found while parsing master.passwd and group PR: 198554 Reported by: diaran MFC after: 2 days --- pw/pw_vpw.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'pw/pw_vpw.c') diff --git a/pw/pw_vpw.c b/pw/pw_vpw.c index 99663be..a23c66e 100644 --- a/pw/pw_vpw.c +++ b/pw/pw_vpw.c @@ -38,6 +38,7 @@ static const char rcsid[] = #include #include #include +#include #include "pwupd.h" @@ -80,6 +81,9 @@ vnextpwent(char const *nam, uid_t uid, int doclose) if (line[linelen - 1 ] == '\n') line[linelen - 1] = '\0'; pw = pw_scan(line, PWSCAN_MASTER); + if (pw == NULL) + errx(EXIT_FAILURE, "Invalid user entry in '%s':" + " '%s'", getpwpath(_MASTERPASSWD), line); if (uid != (uid_t)-1) { if (uid == pw->pw_uid) break; @@ -160,6 +164,9 @@ vnextgrent(char const *nam, gid_t gid, int doclose) if (line[linelen - 1 ] == '\n') line[linelen - 1] = '\0'; gr = gr_scan(line); + if (gr == NULL) + errx(EXIT_FAILURE, "Invalid group entry in '%s':" + " '%s'", getgrpath(_GROUP), line); if (gid != (gid_t)-1) { if (gid == gr->gr_gid) break; -- cgit v1.2.3