return out;
}
-static char *
+static const char *
strdate(krb5_timestamp when)
{
struct tm *tm;
time_t lcltim = ts2tt(when);
tm = localtime(&lcltim);
- strftime(out, sizeof(out), "%a %b %d %H:%M:%S %Z %Y", tm);
+ if (tm == NULL ||
+ strftime(out, sizeof(out), "%a %b %d %H:%M:%S %Z %Y", tm) == 0)
+ strlcpy(out, "(error)", sizeof(out));
return out;
}
extern krb5_context util_context;
extern time_t get_date(char *);
-static char *strdate(krb5_timestamp when)
+static const char *
+strdate(krb5_timestamp when)
{
struct tm *tm;
static char out[40];
time_t lcltim = ts2tt(when);
tm = localtime(&lcltim);
- strftime(out, sizeof(out), "%a %b %d %H:%M:%S %Z %Y", tm);
+ if (tm == NULL ||
+ strftime(out, sizeof(out), "%a %b %d %H:%M:%S %Z %Y", tm) == 0)
+ strlcpy(out, "(error)", sizeof(out));
return out;
}
time_t tstamp;
tstamp = lp->entry->timestamp;
- (void) localtime(&tstamp);
lp->entry->timestamp = tstamp;
fill = ' ';
if (!krb5_timestamp_to_sfstring((krb5_timestamp)lp->entry->
until = princ.last_pwd_change + pol.pw_min_life;
time_string = ctime(&until);
+ if (time_string == NULL)
+ time_string = "(error)";
errstr = error_message(CHPASS_UTIL_PASSWORD_TOO_SOON);
if (strlen(errstr) + strlen(time_string) < msg_len) {
until = ts_incr(princ_ent.last_pwd_change, policy_ent.pw_min_life);
time_string = ctime(&until);
- if (*(ptr = &time_string[strlen(time_string)-1]) == '\n')
+ if (time_string == NULL)
+ time_string = "(error)";
+ else if (*(ptr = &time_string[strlen(time_string)-1]) == '\n')
*ptr = '\0';
snprintf(msg_ret, msg_len, string_text(CHPASS_UTIL_PASSWORD_TOO_SOON),
time_t now;
#ifdef HAVE_STRFTIME
size_t soff;
-#endif /* HAVE_STRFTIME */
+#else
+ char *r;
+#endif
/*
* Format a syslog-esque message of the format:
* dow mon dd hh:mm:ss tzs yyyy\n
* 012345678901234567890123456789
*/
- strncpy(outbuf, ctime(&now) + 4, 15);
+ r = ctime(&now);
+ if (r == NULL)
+ return(-1);
+ strncpy(outbuf, r + 4, 15);
cp += 15;
#endif /* HAVE_STRFTIME */
#ifdef VERBOSE_LOGS
const char *fmt = "%c"; /* This is to get around gcc -Wall warning that
the year returned might be two digits */
-#ifdef HAVE_LOCALTIME_R
- (void) localtime_r(×tamp2, &tmbuf);
-#else
- memcpy(&tmbuf, localtime(×tamp2), sizeof(tmbuf));
-#endif
+ if (localtime_r(×tamp2, &tmbuf) == NULL)
+ return(ENOMEM);
ret = strftime(buffer, buflen, fmt, &tmbuf);
if (ret == 0 || ret == buflen)
return(ENOMEM);
static const unsigned int sftime_format_table_nents =
sizeof(sftime_format_table)/sizeof(sftime_format_table[0]);
-#ifdef HAVE_LOCALTIME_R
tmp = localtime_r(×tamp2, &tmbuf);
-#else
- memcpy((tmp = &tmbuf), localtime(×tamp2), sizeof(tmbuf));
-#endif
+ if (tmp == NULL)
+ return errno;
ndone = 0;
for (i=0; i<sftime_format_table_nents; i++) {
if ((ndone = strftime(buffer, buflen, sftime_format_table[i], tmp)))
}
/* ctime() for uint32_t* */
-static char *
+static const char *
ctime_uint32(uint32_t *time32)
{
time_t tmp;
+ const char *r;
tmp = *time32;
- return ctime(&tmp);
+ r = ctime(&tmp);
+ return (r == NULL) ? "(error)" : r;
}
/* Display time information. */