fa2969
diff -up shadow-4.1.5.1/lib/encrypt.c.crypt-null shadow-4.1.5.1/lib/encrypt.c
fa2969
--- shadow-4.1.5.1/lib/encrypt.c.crypt-null	2010-08-22 15:05:02.000000000 +0200
fa2969
+++ shadow-4.1.5.1/lib/encrypt.c	2013-07-25 12:27:30.438355782 +0200
fa2969
@@ -49,11 +49,10 @@
fa2969
 	if (!cp) {
fa2969
 		/*
fa2969
 		 * Single Unix Spec: crypt() may return a null pointer,
fa2969
-		 * and set errno to indicate an error.  The caller doesn't
fa2969
-		 * expect us to return NULL, so...
fa2969
+		 * and set errno to indicate an error. In this case return
fa2969
+		 * the NULL so the caller can handle appropriately.
fa2969
 		 */
fa2969
-		perror ("crypt");
fa2969
-		exit (EXIT_FAILURE);
fa2969
+		return cp;
fa2969
 	}
fa2969
 
fa2969
 	/* The GNU crypt does not return NULL if the algorithm is not
fa2969
diff -up shadow-4.1.5.1/libmisc/valid.c.crypt-null shadow-4.1.5.1/libmisc/valid.c
fa2969
--- shadow-4.1.5.1/libmisc/valid.c.crypt-null	2010-08-22 21:14:41.000000000 +0200
fa2969
+++ shadow-4.1.5.1/libmisc/valid.c	2013-07-25 12:27:30.440355847 +0200
fa2969
@@ -95,6 +95,7 @@ bool valid (const char *password, const
fa2969
 	 */
fa2969
 
fa2969
 	if (   (NULL != ent->pw_name)
fa2969
+	    && (NULL != encrypted)
fa2969
 	    && (strcmp (encrypted, ent->pw_passwd) == 0)) {
fa2969
 		return true;
fa2969
 	} else {
fa2969
diff -up shadow-4.1.5.1/lib/pwauth.c.crypt-null shadow-4.1.5.1/lib/pwauth.c
fa2969
--- shadow-4.1.5.1/lib/pwauth.c.crypt-null	2009-07-13 00:24:48.000000000 +0200
fa2969
+++ shadow-4.1.5.1/lib/pwauth.c	2013-07-25 12:27:30.438355782 +0200
fa2969
@@ -73,6 +73,7 @@ int pw_auth (const char *cipher,
fa2969
 	char prompt[1024];
fa2969
 	char *clear = NULL;
fa2969
 	const char *cp;
fa2969
+	const char *encrypted;
fa2969
 	int retval;
fa2969
 
fa2969
 #ifdef	SKEY
fa2969
@@ -177,7 +178,11 @@ int pw_auth (const char *cipher,
fa2969
 	 * the results there as well.
fa2969
 	 */
fa2969
 
fa2969
-	retval = strcmp (pw_encrypt (input, cipher), cipher);
fa2969
+	encrypted = pw_encrypt (input, cipher);
fa2969
+	if (encrypted!=NULL)
fa2969
+		retval = strcmp (encrypted, cipher);
fa2969
+	else
fa2969
+		retval = -1;
fa2969
 
fa2969
 #ifdef  SKEY
fa2969
 	/*
fa2969
diff -up shadow-4.1.5.1/src/chgpasswd.c.crypt-null shadow-4.1.5.1/src/chgpasswd.c
fa2969
--- shadow-4.1.5.1/src/chgpasswd.c.crypt-null	2011-12-09 22:31:40.000000000 +0100
fa2969
+++ shadow-4.1.5.1/src/chgpasswd.c	2013-07-25 12:27:30.440355847 +0200
fa2969
@@ -469,6 +469,10 @@ int main (int argc, char **argv)
fa2969
 #endif
fa2969
 			cp = pw_encrypt (newpwd,
fa2969
 			                 crypt_make_salt (crypt_method, arg));
fa2969
+			if (cp == NULL) {
fa2969
+				perror ("crypt");
fa2969
+				exit (EXIT_FAILURE);
fa2969
+			}	
fa2969
 		}
fa2969
 
fa2969
 		/*
fa2969
diff -up shadow-4.1.5.1/src/chpasswd.c.crypt-null shadow-4.1.5.1/src/chpasswd.c
fa2969
--- shadow-4.1.5.1/src/chpasswd.c.crypt-null	2011-12-09 22:31:40.000000000 +0100
fa2969
+++ shadow-4.1.5.1/src/chpasswd.c	2013-07-25 12:27:30.440355847 +0200
fa2969
@@ -492,6 +492,10 @@ int main (int argc, char **argv)
fa2969
 #endif
fa2969
 			cp = pw_encrypt (newpwd,
fa2969
 			                 crypt_make_salt(crypt_method, arg));
fa2969
+			if (cp == NULL) {
fa2969
+				perror ("crypt");
fa2969
+				exit (EXIT_FAILURE);
fa2969
+			}
fa2969
 		}
fa2969
 
fa2969
 		/*
fa2969
diff -up shadow-4.1.5.1/src/gpasswd.c.crypt-null shadow-4.1.5.1/src/gpasswd.c
fa2969
--- shadow-4.1.5.1/src/gpasswd.c.crypt-null	2011-11-19 23:55:04.000000000 +0100
fa2969
+++ shadow-4.1.5.1/src/gpasswd.c	2013-07-25 12:27:30.441355866 +0200
fa2969
@@ -939,6 +939,10 @@ static void change_passwd (struct group
fa2969
 	}
fa2969
 
fa2969
 	cp = pw_encrypt (pass, crypt_make_salt (NULL, NULL));
fa2969
+	if (cp==NULL) {
fa2969
+		perror ("crypt");
fa2969
+		exit (EXIT_FAILURE);
fa2969
+	}
fa2969
 	memzero (pass, sizeof pass);
fa2969
 #ifdef SHADOWGRP
fa2969
 	if (is_shadowgrp) {
fa2969
diff -up shadow-4.1.5.1/src/newgrp.c.crypt-null shadow-4.1.5.1/src/newgrp.c
fa2969
--- shadow-4.1.5.1/src/newgrp.c.crypt-null	2011-07-30 03:50:01.000000000 +0200
fa2969
+++ shadow-4.1.5.1/src/newgrp.c	2013-07-25 12:27:30.442355881 +0200
fa2969
@@ -184,7 +184,8 @@ static void check_perms (const struct gr
fa2969
 		cpasswd = pw_encrypt (cp, grp->gr_passwd);
fa2969
 		strzero (cp);
fa2969
 
fa2969
-		if (grp->gr_passwd[0] == '\0' ||
fa2969
+		if (cpasswd == NULL ||
fa2969
+		    grp->gr_passwd[0] == '\0' ||
fa2969
 		    strcmp (cpasswd, grp->gr_passwd) != 0) {
fa2969
 #ifdef WITH_AUDIT
fa2969
 			snprintf (audit_buf, sizeof(audit_buf),
fa2969
diff -up shadow-4.1.5.1/src/newusers.c.crypt-null shadow-4.1.5.1/src/newusers.c
fa2969
--- shadow-4.1.5.1/src/newusers.c.crypt-null	2011-12-09 22:31:40.000000000 +0100
fa2969
+++ shadow-4.1.5.1/src/newusers.c	2013-07-25 12:27:30.442355881 +0200
fa2969
@@ -387,6 +387,7 @@ static int add_user (const char *name, u
fa2969
 static void update_passwd (struct passwd *pwd, const char *password)
fa2969
 {
fa2969
 	void *crypt_arg = NULL;
fa2969
+	char *cp;
fa2969
 	if (crypt_method != NULL) {
fa2969
 #ifdef USE_SHA_CRYPT
fa2969
 		if (sflg) {
fa2969
@@ -398,9 +399,13 @@ static void update_passwd (struct passwd
fa2969
 	if ((crypt_method != NULL) && (0 == strcmp(crypt_method, "NONE"))) {
fa2969
 		pwd->pw_passwd = (char *)password;
fa2969
 	} else {
fa2969
-		pwd->pw_passwd = pw_encrypt (password,
fa2969
-		                             crypt_make_salt (crypt_method,
fa2969
-		                                              crypt_arg));
fa2969
+		cp=pw_encrypt (password, crypt_make_salt (crypt_method, 
fa2969
+		                                          crypt_arg));
fa2969
+		if (cp == NULL) {
fa2969
+			perror ("crypt");
fa2969
+			exit (EXIT_FAILURE);
fa2969
+		}
fa2969
+		pwd->pw_passwd = cp;
fa2969
 	}
fa2969
 }
fa2969
 #endif				/* !USE_PAM */
fa2969
@@ -412,6 +417,7 @@ static int add_passwd (struct passwd *pw
fa2969
 {
fa2969
 	const struct spwd *sp;
fa2969
 	struct spwd spent;
fa2969
+	char *cp;
fa2969
 
fa2969
 #ifndef USE_PAM
fa2969
 	void *crypt_arg = NULL;
fa2969
@@ -448,7 +454,12 @@ static int add_passwd (struct passwd *pw
fa2969
 		} else {
fa2969
 			const char *salt = crypt_make_salt (crypt_method,
fa2969
 			                                    crypt_arg);
fa2969
-			spent.sp_pwdp = pw_encrypt (password, salt);
fa2969
+			cp = pw_encrypt (password, salt);
fa2969
+			if (cp == NULL) {
fa2969
+				perror ("crypt");
fa2969
+				exit (EXIT_FAILURE);
fa2969
+			}
fa2969
+			spent.sp_pwdp = cp;
fa2969
 		}
fa2969
 		spent.sp_lstchg = (long) time ((time_t *) 0) / SCALE;
fa2969
 		if (0 == spent.sp_lstchg) {
fa2969
@@ -492,7 +503,12 @@ static int add_passwd (struct passwd *pw
fa2969
 		spent.sp_pwdp = (char *)password;
fa2969
 	} else {
fa2969
 		const char *salt = crypt_make_salt (crypt_method, crypt_arg);
fa2969
-		spent.sp_pwdp = pw_encrypt (password, salt);
fa2969
+		cp = pw_encrypt (password, salt);
fa2969
+		if (cp == NULL) {
fa2969
+			perror ("crypt");
fa2969
+			exit (EXIT_FAILURE);
fa2969
+		}
fa2969
+		spent.sp_pwdp = cp;
fa2969
 	}
fa2969
 #else
fa2969
 	/*
fa2969
diff -up shadow-4.1.5.1/src/passwd.c.crypt-null shadow-4.1.5.1/src/passwd.c
fa2969
--- shadow-4.1.5.1/src/passwd.c.crypt-null	2012-02-13 21:32:01.000000000 +0100
fa2969
+++ shadow-4.1.5.1/src/passwd.c	2013-07-25 12:27:30.443355896 +0200
fa2969
@@ -242,7 +242,7 @@ static int new_password (const struct pa
fa2969
 		}
fa2969
 
fa2969
 		cipher = pw_encrypt (clear, crypt_passwd);
fa2969
-		if (strcmp (cipher, crypt_passwd) != 0) {
fa2969
+		if ((cipher == NULL) || (strcmp (cipher, crypt_passwd) != 0)) {
fa2969
 			strzero (clear);
fa2969
 			strzero (cipher);
fa2969
 			SYSLOG ((LOG_WARN, "incorrect password for %s",
fa2969
@@ -349,6 +349,10 @@ static int new_password (const struct pa
fa2969
 	 * Encrypt the password, then wipe the cleartext password.
fa2969
 	 */
fa2969
 	cp = pw_encrypt (pass, crypt_make_salt (NULL, NULL));
fa2969
+	if (cp == NULL) {
fa2969
+		perror ("crypt");
fa2969
+		exit (EXIT_FAILURE);
fa2969
+	}
fa2969
 	memzero (pass, sizeof pass);
fa2969
 
fa2969
 #ifdef HAVE_LIBCRACK_HIST