chpass(1): Check crypt(3) return and handle error appropriately

This change is spiritually similar to the earlier r231994.

PR:		222756
Submitted by:	Lubos Boucek <bouceklubos AT gmail.com>
Obtained from:	DragonflyBSD 2020c8fec4168a5020f984a093224fade3074b25
This commit is contained in:
Conrad Meyer 2017-10-04 01:12:26 +00:00
parent 5e12225140
commit 3cd1f90972

View 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 = "";