passwd: handle NULL pw_passwd when printing password status
When the -S and -a options are used for passwd to list the status of all passwords, there is a chance the pw_passwd field of struct passwd will be NULL. This can be due to 'files compat' being set for passwd in /etc/nsswitch.conf and the usage of some features not available in the 'files' mode (e.g. a plus sign at the start of a line). Example: germ161:~ # grep passwd /etc/nsswitch.conf passwd: files compat germ161:~ # rpm -qa shadow shadow-4.2.1-34.20.x86_64 germ161:~ # grep passwd /etc/nsswitch.conf passwd: files compat germ161:~ # grep + /etc/passwd +@nisgroup germ161:~ # passwd -S -a > /dev/null Segmentation fault (core dumped) With this commit: germ161:~ # passwd -S -a > /dev/null passwd: malformed password data obtained for user +@nisgroup
This commit is contained in:
parent
065aae682c
commit
05388f748d
@ -490,9 +490,12 @@ static void print_status (const struct passwd *pw)
|
||||
((long long)sp->sp_max * SCALE) / DAY,
|
||||
((long long)sp->sp_warn * SCALE) / DAY,
|
||||
((long long)sp->sp_inact * SCALE) / DAY);
|
||||
} else {
|
||||
} else if (NULL != pw->pw_passwd) {
|
||||
(void) printf ("%s %s\n",
|
||||
pw->pw_name, pw_status (pw->pw_passwd));
|
||||
} else {
|
||||
(void) fprintf(stderr, _("%s: malformed password data obtained for user %s\n"),
|
||||
Prog, pw->pw_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user