Blame SOURCES/shadow-4.1.5.1-crypt-null.patch

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