--- embedaddon/sudo/plugins/sudoers/timestr.c 2013/10/14 07:56:35 1.1.1.2 +++ embedaddon/sudo/plugins/sudoers/timestr.c 2014/06/15 16:12:54 1.1.1.3 @@ -44,21 +44,24 @@ get_timestr(time_t tstamp, int log_year) static char buf[128]; struct tm *timeptr; - timeptr = localtime(&tstamp); + if ((timeptr = localtime(&tstamp)) != NULL) { + /* strftime() does not guarantee to NUL-terminate so we must check. */ + buf[sizeof(buf) - 1] = '\0'; + if (strftime(buf, sizeof(buf), log_year ? "%h %e %T %Y" : "%h %e %T", + timeptr) != 0 && buf[sizeof(buf) - 1] == '\0') + return buf; + } - /* strftime() does not guarantee to NUL-terminate so we must check. */ - buf[sizeof(buf) - 1] = '\0'; - if (strftime(buf, sizeof(buf), log_year ? "%h %e %T %Y" : "%h %e %T", - timeptr) != 0 && buf[sizeof(buf) - 1] == '\0') - return buf; - #endif /* HAVE_STRFTIME */ - s = ctime(&tstamp) + 4; /* skip day of the week */ - if (log_year) - s[20] = '\0'; /* avoid the newline */ - else - s[15] = '\0'; /* don't care about year */ + s = ctime(&tstamp); + if (s != NULL) { + s += 4; /* skip day of the week */ + if (log_year) + s[20] = '\0'; /* avoid the newline */ + else + s[15] = '\0'; /* don't care about year */ + } return s; }