pppd: Don't crash if crypt() returns NULL
authorPaul Mackerras <paulus@samba.org>
Sun, 20 May 2012 04:14:55 +0000 (14:14 +1000)
committerPaul Mackerras <paulus@samba.org>
Sun, 20 May 2012 06:49:41 +0000 (16:49 +1000)
It is possible for crypt() to return NULL under some circumstances,
so we need to check the return value before passing it to strcmp().
If we do get NULL from crypt(), treat it as an authentication failure.

Reported-by: Paul Wouters <pwouters@redhat.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
pppd/auth.c
pppd/session.c

index fb71944..883b7f5 100644 (file)
@@ -1442,9 +1442,11 @@ check_passwd(unit, auser, userlen, apasswd, passwdlen, msg)
            }
            if (secret[0] != 0 && !login_secret) {
                /* password given in pap-secrets - must match */
-               if ((cryptpap || strcmp(passwd, secret) != 0)
-                   && strcmp(crypt(passwd, secret), secret) != 0)
-                   ret = UPAP_AUTHNAK;
+               if (cryptpap || strcmp(passwd, secret) != 0) {
+                   char *cbuf = crypt(passwd, secret);
+                   if (!cbuf || strcmp(cbuf, secret) != 0)
+                       ret = UPAP_AUTHNAK;
+               }
            }
        }
        fclose(f);
index 32901a2..56385dd 100644 (file)
@@ -178,6 +178,7 @@ session_start(flags, user, passwd, ttyName, msg)
     bool try_session = 0;
 #else /* #ifdef USE_PAM */
     struct passwd *pw;
+    char *cbuf;
 #ifdef HAS_SHADOW
     struct spwd *spwd;
     struct spwd *getspnam();
@@ -348,8 +349,10 @@ session_start(flags, user, passwd, ttyName, msg)
        /*
         * If no passwd, don't let them login if we're authenticating.
         */
-        if (pw->pw_passwd == NULL || strlen(pw->pw_passwd) < 2
-            || strcmp(crypt(passwd, pw->pw_passwd), pw->pw_passwd) != 0)
+        if (pw->pw_passwd == NULL || strlen(pw->pw_passwd) < 2)
+            return SESSION_FAILED;
+       cbuf = crypt(passwd, pw->pw_passwd);
+       if (!cbuf || strcmp(cbuf, pw->pw_passwd) != 0)
             return SESSION_FAILED;
     }