]> granicus.if.org Git - linux-pam/commitdiff
Make pam_pwhistory and pam_unix tolerant of corrupted opasswd file.
authorTomas Mraz <tmraz@fedoraproject.org>
Mon, 21 Jul 2014 14:31:38 +0000 (16:31 +0200)
committerTomas Mraz <tmraz@fedoraproject.org>
Mon, 21 Jul 2014 14:37:22 +0000 (16:37 +0200)
* modules/pam_pwhistory/opasswd.c (parse_entry): Test for missing fields
in opasswd entry and return error.
* modules/pam_unix/passverify.c (save_old_password): Test for missing fields
in opasswd entry and skip it.

modules/pam_pwhistory/opasswd.c
modules/pam_unix/passverify.c

index 836d713ea76e4d7f0128921074dc4c5f4fdde50e..e6cf3469781696fd78c4d1dc68e01dac9932257f 100644 (file)
@@ -82,10 +82,15 @@ parse_entry (char *line, opwd *data)
 {
   const char delimiters[] = ":";
   char *endptr;
+  char *count;
 
   data->user = strsep (&line, delimiters);
   data->uid = strsep (&line, delimiters);
-  data->count = strtol (strsep (&line, delimiters), &endptr, 10);
+  count = strsep (&line, delimiters);
+  if (count == NULL)
+      return 1;
+
+  data->count = strtol (count, &endptr, 10);
   if (endptr != NULL && *endptr != '\0')
       return 1;
 
index 4840bb2dcd8c0c96dcf971cd971d365eaca46235..7f7bc4901182e63a4fa0439f43b62727171c16f2 100644 (file)
@@ -639,11 +639,23 @@ save_old_password(pam_handle_t *pamh, const char *forwho, const char *oldpass,
                continue;
            buf[strlen(buf) - 1] = '\0';
            s_luser = strtok_r(buf, ":", &sptr);
+           if (s_luser == NULL) {
+               found = 0;
+               continue;
+           }
            s_uid = strtok_r(NULL, ":", &sptr);
+           if (s_uid == NULL) {
+               found = 0;
+               continue;
+           }
            s_npas = strtok_r(NULL, ":", &sptr);
+           if (s_npas == NULL) {
+               found = 0;
+               continue;
+           }
            s_pas = strtok_r(NULL, ":", &sptr);
            npas = strtol(s_npas, NULL, 10) + 1;
-           while (npas > howmany) {
+           while (npas > howmany && s_pas != NULL) {
                s_pas = strpbrk(s_pas, ",");
                if (s_pas != NULL)
                    s_pas++;