]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
passwd: handle NULL pw_passwd when printing password status 398/head
authorJaroslav Jindrak <dzejrou@gmail.com>
Tue, 3 Aug 2021 18:03:46 +0000 (20:03 +0200)
committerJaroslav Jindrak <dzejrou@gmail.com>
Tue, 3 Aug 2021 18:03:46 +0000 (20:03 +0200)
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

src/passwd.c

index 9d7df3313706724e01fed0b672a4c63642d75b84..9d33d25e5b44be06290ce3591bf0efca0613eaa9 100644 (file)
@@ -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);
        }
 }