]> git.cameronkatri.com Git - pw-darwin.git/commitdiff
chpass(1): Check crypt(3) return and handle error appropriately
authorConrad Meyer <cem@FreeBSD.org>
Wed, 4 Oct 2017 01:12:26 +0000 (01:12 +0000)
committerConrad Meyer <cem@FreeBSD.org>
Wed, 4 Oct 2017 01:12:26 +0000 (01:12 +0000)
This change is spiritually similar to the earlier r231994.

PR: 222756
Submitted by: Lubos Boucek <bouceklubos AT gmail.com>
Obtained from: DragonflyBSD 2020c8fec4168a5020f984a093224fade3074b25

chpass/chpass.c

index 9f9be5335a682376d0d8063669fbae7f20d45670..74c96beb92e7acd4e2275a25671f9a692b16ae1f 100644 (file)
@@ -82,7 +82,7 @@ main(int argc, char *argv[])
        struct passwd lpw, *old_pw, *pw;
        int ch, pfd, tfd;
        const char *password;
-       char *arg = NULL;
+       char *arg = NULL, *cryptpw;
        uid_t uid;
 #ifdef YP
        struct ypclnt *ypclnt;
@@ -228,8 +228,8 @@ main(int argc, char *argv[])
 
        if (old_pw && !master_mode) {
                password = getpass("Password: ");
-               if (strcmp(crypt(password, old_pw->pw_passwd),
-                   old_pw->pw_passwd) != 0)
+               cryptpw = crypt(password, old_pw->pw_passwd);
+               if (cryptpw == NULL || strcmp(cryptpw, old_pw->pw_passwd) != 0)
                        baduser();
        } else {
                password = "";