]> granicus.if.org Git - linux-pam/commitdiff
Add checks for localtime() returning NULL.
authorTomas Mraz <tmraz@fedoraproject.org>
Fri, 4 Mar 2016 13:19:01 +0000 (14:19 +0100)
committerTomas Mraz <tmraz@fedoraproject.org>
Fri, 4 Mar 2016 13:19:01 +0000 (14:19 +0100)
* modules/pam_lastlog/pam_lastlog.c (last_login_read): Check for localtime_r
returning NULL.
* modules/pam_tally2/pam_tally2.c (print_one): Check for localtime returning
NULL.

modules/pam_lastlog/pam_lastlog.c
modules/pam_tally2/pam_tally2.c

index 50d33e40af63b60550dcb604b23733044f3db06f..76a33e4128e0a2343fa3ddd2911211d0e6cc93cc 100644 (file)
@@ -276,12 +276,12 @@ last_login_read(pam_handle_t *pamh, int announce, int last_fd, uid_t uid, time_t
                time_t ll_time;
 
                ll_time = last_login.ll_time;
-               tm = localtime_r (&ll_time, &tm_buf);
-               strftime (the_time, sizeof (the_time),
-               /* TRANSLATORS: "strftime options for date of last login" */
-                         _(" %a %b %e %H:%M:%S %Z %Y"), tm);
-
-               date = the_time;
+               if ((tm = localtime_r (&ll_time, &tm_buf)) != NULL) {
+                       strftime (the_time, sizeof (the_time),
+                       /* TRANSLATORS: "strftime options for date of last login" */
+                                 _(" %a %b %e %H:%M:%S %Z %Y"), tm);
+                       date = the_time;
+               }
            }
 
            /* we want & have the host? */
index e513f64c9c7f73d08f54b4a206ebc7c67b0fc7bf..9187cbfd7a34e008bea14f8ede0b7fa7431da00d 100644 (file)
@@ -924,7 +924,7 @@ static void
 print_one(const struct tallylog *tally, uid_t uid)
 {
    static int once;
-   char *cp;
+   char *cp = "[UNKNOWN]";
    time_t fail_time;
    struct tm *tm;
    struct passwd *pwent;
@@ -933,9 +933,10 @@ print_one(const struct tallylog *tally, uid_t uid)
 
    pwent = getpwuid(uid);
    fail_time = tally->fail_time;
-   tm = localtime(&fail_time);
-   strftime (ptime, sizeof (ptime), "%D %H:%M:%S", tm);
-   cp = ptime;
+   if ((tm = localtime(&fail_time)) != NULL) {
+        strftime (ptime, sizeof (ptime), "%D %H:%M:%S", tm);
+        cp = ptime;
+   }
    if (pwent) {
         username = pwent->pw_name;
    }