components/cyrus-sasl/patches/1-cyrus-sasl-CVE-4122.patch
author Patrick Einheber <patrick.einheber@oracle.com>
Wed, 12 Oct 2016 08:38:46 -0700
changeset 7093 a50590d00730
parent 5055 9daf220c1a9a
permissions -rw-r--r--
24710648 puppet resource LDAP lookup fails when querying users

This patch was re-made from a commit on cgit.cyrus.foundation at this
URL:  
https://cgit.cyrus.foundation/cyrus-sasl/commit/?id=dedad73e5e7a75d01a5f3d5a6702ab8ccd2ff40d

Probably not needed for Solaris but it's better to just have the fix.

"Handle NULL returns from glibc 2.17+ crypt()
Starting with glibc 2.17 (eglibc 2.17), crypt() fails with EINVAL
(w/ NULL return) if the salt violates specifications. Additionally,
on FIPS-140 enabled Linux systems, DES/MD5-encrypted passwords
passed to crypt() fail with EPERM (w/ NULL return).

When using glibc's crypt(), check return value to avoid a possible NULL pointer dereference. Patch by [email protected].
"

diff -rupN old/pwcheck/pwcheck_getpwnam.c new/pwcheck/pwcheck_getpwnam.c
--- old/pwcheck/pwcheck_getpwnam.c	2015-04-07 17:03:52.497417754 -0700
+++ new/pwcheck/pwcheck_getpwnam.c	2013-07-11 07:56:26.000000000 -0700
@@ -32,6 +32,7 @@ char *userid;
 char *password;
 {
     char* r;
+    char* crpt_passwd;
     struct passwd *pwd;
 
     pwd = getpwnam(userid);
@@ -41,7 +42,7 @@ char *password;
     else if (pwd->pw_passwd[0] == '*') {
 	r = "Account disabled";
     }
-    else if (strcmp(pwd->pw_passwd, crypt(password, pwd->pw_passwd)) != 0) {
+    else if (!(crpt_passwd = crypt(password, pwd->pw_passwd)) || strcmp(pwd->pw_passwd, (const char *)crpt_passwd) != 0) {
 	r = "Incorrect password";
     }
     else {
diff -rupN old/pwcheck/pwcheck_getspnam.c new/pwcheck/pwcheck_getspnam.c
--- old/pwcheck/pwcheck_getspnam.c	2015-04-07 17:03:52.508074499 -0700
+++ new/pwcheck/pwcheck_getspnam.c	2013-07-11 07:56:26.000000000 -0700
@@ -32,13 +32,15 @@ char *userid;
 char *password;
 {
     struct spwd *pwd;
+    char *crpt_passwd;
 
     pwd = getspnam(userid);
     if (!pwd) {
 	return "Userid not found";
     }
     
-    if (strcmp(pwd->sp_pwdp, crypt(password, pwd->sp_pwdp)) != 0) {
+    crpt_passwd = crypt(password, pwd->sp_pwdp);
+    if (!crpt_passwd || strcmp(pwd->sp_pwdp, (const char *)crpt_passwd) != 0) {
 	return "Incorrect password";
     }
     else {
diff -rupN old/saslauthd/auth_getpwent.c new/saslauthd/auth_getpwent.c
--- old/saslauthd/auth_getpwent.c	2015-04-07 17:04:22.961304455 -0700
+++ new/saslauthd/auth_getpwent.c	2013-07-11 07:56:26.000000000 -0700
@@ -77,6 +77,7 @@ auth_getpwent (
 {
     /* VARIABLES */
     struct passwd *pw;			/* pointer to passwd file entry */
+    char *crpt_passwd;			/* encrypted password */
     int errnum;
     /* END VARIABLES */
   
@@ -105,7 +106,8 @@ auth_getpwent (
 	}
     }
 
-    if (strcmp(pw->pw_passwd, (const char *)crypt(password, pw->pw_passwd))) {
+    crpt_passwd = crypt(password, pw->pw_passwd);
+    if (!crpt_passwd || strcmp(pw->pw_passwd, (const char *)crpt_passwd)) {
 	if (flags & VERBOSE) {
 	    syslog(LOG_DEBUG, "DEBUG: auth_getpwent: %s: invalid password", login);
 	}
diff -rupN old/saslauthd/auth_shadow.c new/saslauthd/auth_shadow.c
--- old/saslauthd/auth_shadow.c	2015-04-07 17:04:22.968116900 -0700
+++ new/saslauthd/auth_shadow.c	2013-07-11 07:56:26.000000000 -0700
@@ -210,8 +210,8 @@ auth_shadow (
 	RETURN("NO Insufficient permission to access NIS authentication database (saslauthd)");
     }
 
-    cpw = strdup((const char *)crypt(password, sp->sp_pwdp));
-    if (strcmp(sp->sp_pwdp, cpw)) {
+    cpw = crypt(password, sp->sp_pwdp);
+    if (!cpw || strcmp(sp->sp_pwdp, (const char *)cpw)) {
 	if (flags & VERBOSE) {
 	    /*
 	     * This _should_ reveal the SHADOW_PW_LOCKED prefix to an
@@ -221,10 +221,8 @@ auth_shadow (
 	    syslog(LOG_DEBUG, "DEBUG: auth_shadow: pw mismatch: '%s' != '%s'",
 		   sp->sp_pwdp, cpw);
 	}
-	free(cpw);
 	RETURN("NO Incorrect password");
     }
-    free(cpw);
 
     /*
      * The following fields will be set to -1 if:
@@ -286,7 +284,7 @@ auth_shadow (
 	RETURN("NO Invalid username");
     }
   
-    if (strcmp(upw->upw_passwd, crypt(password, upw->upw_passwd)) != 0) {
+    if (!(cpw = crypt(password, upw->upw_passwd)) || (strcmp(upw->upw_passwd, (const char *)cpw) != 0)) {
 	if (flags & VERBOSE) {
 	    syslog(LOG_DEBUG, "auth_shadow: pw mismatch: %s != %s",
 		   password, upw->upw_passwd);