]> granicus.if.org Git - shadow/commitdiff
crypt() in glibc/eglibc 2.17 now fails if passed
authormancha <mancha1@hush.com>
Sun, 28 Jul 2013 16:41:11 +0000 (18:41 +0200)
committerbubulle <bubulle@debian.org>
Sun, 28 Jul 2013 16:41:11 +0000 (18:41 +0200)
a salt that violates specs. On Linux, crypt() also fails with
DES/MD5 salts in FIPS140 mode. Rather than exit() on NULL returns
we send them back to the caller for appropriate handling.

ChangeLog
lib/encrypt.c
lib/pwauth.c
libmisc/valid.c
src/chgpasswd.c
src/chpasswd.c
src/gpasswd.c
src/newgrp.c
src/newusers.c
src/passwd.c

index 1955f3b0396dac8e449c51a85a85100f9106dd49..104caa07e886e397fde036f310802bc88423e9fe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2013-07-28  mancha <mancha1@hush.com>
+
+        * lib/encrypt.c: crypt() in glibc/eglibc 2.17 now fails if passed
+          a salt that violates specs. On Linux, crypt() also fails with
+          DES/MD5 salts in FIPS140 mode. Rather than exit() on NULL returns
+          we send them back to the caller for appropriate handling.
+        * lib/pwauth.c: Handle NULL return from crypt().
+        * libmisc/valid.c: Likewise.
+        * src/chgpasswd.c: Likewise.
+        * src/chpasswd.c: Likewise.
+        * src/gpasswd.c: Likewise.
+        * src/newgrp.c: Likewise.
+        * src/newusers.c: Likewise.
+        * src/passwd.c: Likewise.
+
 2013-07-28  Christian Perrier  <christian@perrier.eu.org>
 
        * configure.in: Prepare for next point release 4.2.
index 7daa8da173c1416dda7eb16fbd089114e0390345..7ff8b5061122269f3ac7ff8c61765fc14cc6f0f7 100644 (file)
        if (!cp) {
                /*
                 * Single Unix Spec: crypt() may return a null pointer,
-                * and set errno to indicate an error.  The caller doesn't
-                * expect us to return NULL, so...
+                * and set errno to indicate an error. In this case return
+                * the NULL so the caller can handle appropriately.
                 */
-               perror ("crypt");
-               exit (EXIT_FAILURE);
+               return cp;
        }
 
        /* The GNU crypt does not return NULL if the algorithm is not
index 4b26daa786684c7cea718ecca77822a7a6f63f5b..086a72e2155741b7cf9e675df93f27c3dbc0754a 100644 (file)
@@ -73,6 +73,7 @@ int pw_auth (const char *cipher,
        char prompt[1024];
        char *clear = NULL;
        const char *cp;
+       const char *encrypted;
        int retval;
 
 #ifdef SKEY
@@ -177,7 +178,11 @@ int pw_auth (const char *cipher,
         * the results there as well.
         */
 
-       retval = strcmp (pw_encrypt (input, cipher), cipher);
+       encrypted = pw_encrypt (input, cipher);
+       if (encrypted!=NULL)
+               retval = strcmp (encrypted, cipher);
+       else
+               retval = -1;
 
 #ifdef  SKEY
        /*
index aa0390a550749e5e1a9ae93b3d130965a711bb83..4b85d67c9b654042210d5d2ba6a298ad00a67753 100644 (file)
@@ -95,6 +95,7 @@ bool valid (const char *password, const struct passwd *ent)
         */
 
        if (   (NULL != ent->pw_name)
+           && (NULL != encrypted)
            && (strcmp (encrypted, ent->pw_passwd) == 0)) {
                return true;
        } else {
index 0f41d0be2d792a56d060fd44ba0cb24cb5b3b889..6c42a096ac886bcde0b2507d4692047b982148bd 100644 (file)
@@ -469,6 +469,10 @@ int main (int argc, char **argv)
 #endif
                        cp = pw_encrypt (newpwd,
                                         crypt_make_salt (crypt_method, arg));
+                       if (cp == NULL) {
+                               perror ("crypt");
+                               exit (EXIT_FAILURE);
+                       }       
                }
 
                /*
index 928e2d7528191734f088b4be88ebf2f5b96034e2..4968b0d260f8e8e3e54035d11e239df00dd13d02 100644 (file)
@@ -492,6 +492,10 @@ int main (int argc, char **argv)
 #endif
                        cp = pw_encrypt (newpwd,
                                         crypt_make_salt(crypt_method, arg));
+                       if (cp == NULL) {
+                               perror ("crypt");
+                               exit (EXIT_FAILURE);
+                       }
                }
 
                /*
index df8d714877d6075bb7b14d2cdd8407d292f8feb0..0043610658fe6518ce567765855907f4485529d7 100644 (file)
@@ -939,6 +939,10 @@ static void change_passwd (struct group *gr)
        }
 
        cp = pw_encrypt (pass, crypt_make_salt (NULL, NULL));
+       if (cp==NULL) {
+               perror ("crypt");
+               exit (EXIT_FAILURE);
+       }
        memzero (pass, sizeof pass);
 #ifdef SHADOWGRP
        if (is_shadowgrp) {
index 9330c72129b93ae4312fc9132d591b24c9cc0062..6b8776180ae0932a78443735a7ad1c9616727f0f 100644 (file)
@@ -184,7 +184,8 @@ static void check_perms (const struct group *grp,
                cpasswd = pw_encrypt (cp, grp->gr_passwd);
                strzero (cp);
 
-               if (grp->gr_passwd[0] == '\0' ||
+               if (cpasswd == NULL ||
+                   grp->gr_passwd[0] == '\0' ||
                    strcmp (cpasswd, grp->gr_passwd) != 0) {
 #ifdef WITH_AUDIT
                        snprintf (audit_buf, sizeof(audit_buf),
index 994898e3514295ad0afd9ecd8819cabfa9d98771..5f83a6a5c763f2f574b11c2e7cf2a8a5b433e424 100644 (file)
@@ -387,6 +387,7 @@ static int add_user (const char *name, uid_t uid, gid_t gid)
 static void update_passwd (struct passwd *pwd, const char *password)
 {
        void *crypt_arg = NULL;
+       char *cp;
        if (crypt_method != NULL) {
 #ifdef USE_SHA_CRYPT
                if (sflg) {
@@ -398,9 +399,13 @@ static void update_passwd (struct passwd *pwd, const char *password)
        if ((crypt_method != NULL) && (0 == strcmp(crypt_method, "NONE"))) {
                pwd->pw_passwd = (char *)password;
        } else {
-               pwd->pw_passwd = pw_encrypt (password,
-                                            crypt_make_salt (crypt_method,
-                                                             crypt_arg));
+               cp=pw_encrypt (password, crypt_make_salt (crypt_method, 
+                                                         crypt_arg));
+               if (cp == NULL) {
+                       perror ("crypt");
+                       exit (EXIT_FAILURE);
+               }
+               pwd->pw_passwd = cp;
        }
 }
 #endif                         /* !USE_PAM */
@@ -412,6 +417,7 @@ static int add_passwd (struct passwd *pwd, const char *password)
 {
        const struct spwd *sp;
        struct spwd spent;
+       char *cp;
 
 #ifndef USE_PAM
        void *crypt_arg = NULL;
@@ -448,7 +454,12 @@ static int add_passwd (struct passwd *pwd, const char *password)
                } else {
                        const char *salt = crypt_make_salt (crypt_method,
                                                            crypt_arg);
-                       spent.sp_pwdp = pw_encrypt (password, salt);
+                       cp = pw_encrypt (password, salt);
+                       if (cp == NULL) {
+                               perror ("crypt");
+                               exit (EXIT_FAILURE);
+                       }
+                       spent.sp_pwdp = cp;
                }
                spent.sp_lstchg = (long) time ((time_t *) 0) / SCALE;
                if (0 == spent.sp_lstchg) {
@@ -492,7 +503,12 @@ static int add_passwd (struct passwd *pwd, const char *password)
                spent.sp_pwdp = (char *)password;
        } else {
                const char *salt = crypt_make_salt (crypt_method, crypt_arg);
-               spent.sp_pwdp = pw_encrypt (password, salt);
+               cp = pw_encrypt (password, salt);
+               if (cp == NULL) {
+                       perror ("crypt");
+                       exit (EXIT_FAILURE);
+               }
+               spent.sp_pwdp = cp;
        }
 #else
        /*
index ac90aa3034d20c87d21ef3dd1fd83a8dc49d6371..ae2666610d8902e2fd3217b235993454d1baf063 100644 (file)
@@ -242,7 +242,7 @@ static int new_password (const struct passwd *pw)
                }
 
                cipher = pw_encrypt (clear, crypt_passwd);
-               if (strcmp (cipher, crypt_passwd) != 0) {
+               if ((cipher == NULL) || (strcmp (cipher, crypt_passwd) != 0)) {
                        strzero (clear);
                        strzero (cipher);
                        SYSLOG ((LOG_WARN, "incorrect password for %s",
@@ -349,6 +349,10 @@ static int new_password (const struct passwd *pw)
         * Encrypt the password, then wipe the cleartext password.
         */
        cp = pw_encrypt (pass, crypt_make_salt (NULL, NULL));
+       if (cp == NULL) {
+               perror ("crypt");
+               exit (EXIT_FAILURE);
+       }
        memzero (pass, sizeof pass);
 
 #ifdef HAVE_LIBCRACK_HIST