]> granicus.if.org Git - linux-pam/commitdiff
Guards for memory allocation errors in pam_cracklib module.
authorTomas Mraz <tmraz@fedoraproject.org>
Thu, 2 Jun 2011 19:53:55 +0000 (21:53 +0200)
committerTomas Mraz <tmraz@fedoraproject.org>
Thu, 2 Jun 2011 19:53:55 +0000 (21:53 +0200)
ChangeLog
modules/pam_cracklib/pam_cracklib.c

index e91af88b3995f32db85204ce627809e425042749..7af2a8693745a2b6a95b1dbf8047c3e6897171f3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,10 @@
        * modules/pam_namespace/pam_namespace.8.xml: Document the mount_private
        option.
 
+       * modules/pam_cracklib/pam_cracklib.c (str_lower): Make it no-op
+       on NULL strings.
+       (password_check): Guard for NULLs returned from memory allocation.
+
 2011-05-30  Thorsten Kukuk  <kukuk@thkukuk.de>
 
        * modules/pam_timestamp/pam_timestamp.c (main): Remove unsused
index 2e911261f83c229aec821850c7f8aed3dc012acd..1955b83ffe5547f49a69952841ff2ad7ab9f493e 100644 (file)
@@ -473,6 +473,9 @@ static char * str_lower(char *string)
 {
        char *cp;
 
+       if (!string)
+               return NULL;
+
        for (cp = string; *cp; cp++)
                *cp = tolower(*cp);
        return string;
@@ -492,15 +495,26 @@ static const char *password_check(struct cracklib_options *opt,
        }
 
        newmono = str_lower(x_strdup(new));
+       if (!newmono)
+               msg = _("memory allocation error");
+
        usermono = str_lower(x_strdup(user));
-       if (old) {
-         oldmono = str_lower(x_strdup(old));
-         wrapped = malloc(strlen(oldmono) * 2 + 1);
-         strcpy (wrapped, oldmono);
-         strcat (wrapped, oldmono);
+       if (!usermono)
+               msg = _("memory allocation error");
+
+       if (!msg && old) {
+               oldmono = str_lower(x_strdup(old));
+               if (oldmono)
+                       wrapped = malloc(strlen(oldmono) * 2 + 1);
+               if (wrapped) {
+                       strcpy (wrapped, oldmono);
+                       strcat (wrapped, oldmono);
+               } else {
+                       msg = _("memory allocation error");
+               }
        }
 
-       if (palindrome(newmono))
+       if (!msg && palindrome(newmono))
                msg = _("is a palindrome");
 
        if (!msg && oldmono && strcmp(oldmono, newmono) == 0)
@@ -524,13 +538,17 @@ static const char *password_check(struct cracklib_options *opt,
        if (!msg && usercheck(opt, newmono, usermono))
                msg = _("contains the user name in some form");
 
-       memset(newmono, 0, strlen(newmono));
-       free(newmono);
        free(usermono);
-       if (old) {
+       if (newmono) {
+               memset(newmono, 0, strlen(newmono));
+               free(newmono);
+       }
+       if (oldmono) {
          memset(oldmono, 0, strlen(oldmono));
-         memset(wrapped, 0, strlen(wrapped));
          free(oldmono);
+       }
+       if (wrapped) {
+         memset(wrapped, 0, strlen(wrapped));
          free(wrapped);
        }