From cc6f628176f0424fa706509a75b43998934af12d Mon Sep 17 00:00:00 2001 From: David Greenman Date: Fri, 27 Jan 1995 22:30:03 +0000 Subject: [PATCH] Be sure to properly fail if there are not enough fields. Problem reported by MARC Giannoni , this fix is by me. --- lib/libc/gen/pw_scan.c | 6 ++++-- usr.sbin/pwd_mkdb/pw_scan.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/libc/gen/pw_scan.c b/lib/libc/gen/pw_scan.c index fbefc5b3631f..602006e4c4dd 100644 --- a/lib/libc/gen/pw_scan.c +++ b/lib/libc/gen/pw_scan.c @@ -110,10 +110,12 @@ pw_scan(bp, pw) if(p[0]) pw->pw_fields |= _PWF_EXPIRE; pw->pw_expire = atol(p); - pw->pw_gecos = strsep(&bp, ":"); /* gecos */ + if (!(pw->pw_gecos = strsep(&bp, ":"))) /* gecos */ + goto fmt; if(pw->pw_gecos[0]) pw->pw_fields |= _PWF_GECOS; - pw->pw_dir = strsep(&bp, ":"); /* directory */ + if (!(pw->pw_dir = strsep(&bp, ":"))) /* directory */ + goto fmt; if(pw->pw_dir[0]) pw->pw_fields |= _PWF_DIR; if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */ diff --git a/usr.sbin/pwd_mkdb/pw_scan.c b/usr.sbin/pwd_mkdb/pw_scan.c index fbefc5b3631f..602006e4c4dd 100644 --- a/usr.sbin/pwd_mkdb/pw_scan.c +++ b/usr.sbin/pwd_mkdb/pw_scan.c @@ -110,10 +110,12 @@ pw_scan(bp, pw) if(p[0]) pw->pw_fields |= _PWF_EXPIRE; pw->pw_expire = atol(p); - pw->pw_gecos = strsep(&bp, ":"); /* gecos */ + if (!(pw->pw_gecos = strsep(&bp, ":"))) /* gecos */ + goto fmt; if(pw->pw_gecos[0]) pw->pw_fields |= _PWF_GECOS; - pw->pw_dir = strsep(&bp, ":"); /* directory */ + if (!(pw->pw_dir = strsep(&bp, ":"))) /* directory */ + goto fmt; if(pw->pw_dir[0]) pw->pw_fields |= _PWF_DIR; if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */