-/* $OpenBSD: dhclient.c,v 1.727 2022/07/02 17:21:32 deraadt Exp $ */
+/* $OpenBSD: dhclient.c,v 1.728 2024/04/28 16:43:42 florian Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
static char string[8192];
char timebuf[27]; /* 6 2017/04/08 05:47:50 UTC; */
struct option_data *opt;
+ struct tm *tm;
char *buf, *name;
time_t t;
size_t rslt;
free(buf);
t = lease->epoch + lease_renewal(lease);
- rslt = strftime(timebuf, sizeof(timebuf), DB_TIMEFMT, gmtime(&t));
+ if ((tm = gmtime(&t)) == NULL)
+ return NULL;
+ rslt = strftime(timebuf, sizeof(timebuf), DB_TIMEFMT, tm);
if (rslt == 0)
return NULL;
append_statement(string, sizeof(string), " renew ", timebuf);
t = lease->epoch + lease_rebind(lease);
- rslt = strftime(timebuf, sizeof(timebuf), DB_TIMEFMT, gmtime(&t));
+ if ((tm = gmtime(&t)) == NULL)
+ return NULL;
+ rslt = strftime(timebuf, sizeof(timebuf), DB_TIMEFMT, tm);
if (rslt == 0)
return NULL;
append_statement(string, sizeof(string), " rebind ", timebuf);
t = lease->epoch + lease_expiry(lease);
- rslt = strftime(timebuf, sizeof(timebuf), DB_TIMEFMT, gmtime(&t));
+ if ((tm = gmtime(&t)) == NULL)
+ return NULL;
+ rslt = strftime(timebuf, sizeof(timebuf), DB_TIMEFMT, tm);
if (rslt == 0)
return NULL;
append_statement(string, sizeof(string), " expire ", timebuf);
-/* $OpenBSD: log.c,v 1.64 2018/01/15 09:54:48 mpi Exp $ */
+/* $OpenBSD: log.c,v 1.65 2024/04/28 16:43:42 florian Exp $ */
/* $EOM: log.c,v 1.30 2000/09/29 08:19:23 niklas Exp $ */
/*
if (log_output) {
gettimeofday(&now, 0);
t = now.tv_sec;
- tm = localtime(&t);
+ if ((tm = localtime(&t)) == NULL) {
+ /* Invalid time, use the epoch. */
+ t = 0;
+ tm = localtime(&t);
+ }
if (class >= 0)
snprintf(nbuf, sizeof nbuf,
"%02d%02d%02d.%06ld %s %02d ",
-/* $OpenBSD: policy.c,v 1.102 2021/10/22 12:30:54 bluhm Exp $ */
+/* $OpenBSD: policy.c,v 1.103 2024/04/28 16:43:42 florian Exp $ */
/* $EOM: policy.c,v 1.49 2000/10/24 13:33:39 niklas Exp $ */
/*
return phase_1;
if (strcmp(name, "GMTTimeOfDay") == 0) {
+ struct tm *tm;
tt = time(NULL);
- strftime(mytimeofday, 14, "%Y%m%d%H%M%S", gmtime(&tt));
+ if ((tm = gmtime(&tt)) == NULL) {
+ log_error("policy_callback: invalid time %lld", tt);
+ goto bad;
+ }
+ strftime(mytimeofday, 14, "%Y%m%d%H%M%S", tm);
return mytimeofday;
}
if (strcmp(name, "LocalTimeOfDay") == 0) {
+ struct tm *tm;
tt = time(NULL);
- strftime(mytimeofday, 14, "%Y%m%d%H%M%S", localtime(&tt));
+ if ((tm = localtime(&tt)) == NULL) {
+ log_error("policy_callback: invalid time %lld", tt);
+ goto bad;
+ }
+ strftime(mytimeofday, 14, "%Y%m%d%H%M%S", tm);
return mytimeofday;
}
if (strcmp(name, "initiator") == 0)
-/* $OpenBSD: x509.c,v 1.125 2022/01/16 14:30:11 naddy Exp $ */
+/* $OpenBSD: x509.c,v 1.126 2024/04/28 16:43:42 florian Exp $ */
/* $EOM: x509.c,v 1.54 2001/01/16 18:42:16 ho Exp $ */
/*
if (((tm = X509_get_notBefore(cert)) == NULL) ||
(tm->type != V_ASN1_UTCTIME &&
tm->type != V_ASN1_GENERALIZEDTIME)) {
- tt = time(0);
- strftime(before, 14, "%Y%m%d%H%M%S", localtime(&tt));
+ struct tm *ltm;
+
+ tt = time(NULL);
+ if ((ltm = localtime(&tt)) == NULL) {
+ LOG_DBG((LOG_POLICY, 30,
+ "x509_generate_kn: invalid local time"));
+ goto fail;
+ }
+ strftime(before, 14, "%Y%m%d%H%M%S", ltm);
timecomp = "LocalTimeOfDay";
} else {
if (tm->data[tm->length - 1] == 'Z') {
if (tm == NULL ||
(tm->type != V_ASN1_UTCTIME &&
tm->type != V_ASN1_GENERALIZEDTIME)) {
+ struct tm *ltm;
+
tt = time(0);
- strftime(after, 14, "%Y%m%d%H%M%S", localtime(&tt));
+ if ((ltm = localtime(&tt)) == NULL) {
+ LOG_DBG((LOG_POLICY, 30,
+ "x509_generate_kn: invalid local time"));
+ goto fail;
+ }
+ strftime(after, 14, "%Y%m%d%H%M%S", ltm);
timecomp2 = "LocalTimeOfDay";
} else {
if (tm->data[tm->length - 1] == 'Z') {
-/* $OpenBSD: newfs_msdos.c,v 1.28 2021/07/11 15:39:58 kettenis Exp $ */
+/* $OpenBSD: newfs_msdos.c,v 1.29 2024/04/28 16:43:42 florian Exp $ */
/*
* Copyright (c) 1998 Robert Nordier
if (!opt_N) {
gettimeofday(&tv, NULL);
now = tv.tv_sec;
- tm = localtime(&now);
+ if ((tm = localtime(&now)) == NULL)
+ errx(1, "Invalid time");
+
if (!(img = malloc(bpb.bps)))
err(1, NULL);
dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft;
-/* $OpenBSD: route.c,v 1.265 2023/03/17 16:11:09 claudio Exp $ */
+/* $OpenBSD: route.c,v 1.266 2024/04/28 16:43:42 florian Exp $ */
/* $NetBSD: route.c,v 1.16 1996/04/15 18:27:05 cgd Exp $ */
/*
fmt = "%Ss";
tp = localtime(&time);
- (void)strftime(buf, sizeof(buf), fmt, tp);
+ if (tp)
+ (void)strftime(buf, sizeof(buf), fmt, tp);
+ else
+ buf[0] = '\0';
return (buf);
}
-/* $OpenBSD: shutdown.c,v 1.55 2023/04/19 12:58:15 jsg Exp $ */
+/* $OpenBSD: shutdown.c,v 1.56 2024/04/28 16:43:42 florian Exp $ */
/* $NetBSD: shutdown.c,v 1.9 1995/03/18 15:01:09 cgd Exp $ */
/*
if (timeleft > 10 * 60) {
shuttime = time(NULL) + timeleft;
lt = localtime(&shuttime);
- strftime(when, sizeof(when), "%H:%M %Z", lt);
- dprintf(fd[1], "System going down at %s\n\n", when);
+ if (lt != NULL) {
+ strftime(when, sizeof(when), "%H:%M %Z", lt);
+ dprintf(fd[1], "System going down at %s\n\n", when);
+ } else
+ dprintf(fd[1], "System going down in %lld minute%s\n\n",
+ (long long)(timeleft / 60),
+ (timeleft > 60) ? "s" : "");
} else if (timeleft > 59) {
dprintf(fd[1], "System going down in %lld minute%s\n\n",
(long long)(timeleft / 60), (timeleft > 60) ? "s" : "");
time(&now);
lt = localtime(&now); /* current time val */
+ if (lt == NULL)
+ badtime();
+
switch (strlen(timearg)) {
case 10:
this_year = lt->tm_year;
(void)signal(SIGTERM, finish);
shuttime = time(NULL) + timeleft;
tm = localtime(&shuttime);
- if (tm && (logfd = open(_PATH_NOLOGIN, O_WRONLY|O_CREAT|O_TRUNC,
+ if ((logfd = open(_PATH_NOLOGIN, O_WRONLY|O_CREAT|O_TRUNC,
0664)) >= 0) {
- strftime(when, sizeof(when), "at %H:%M %Z", tm);
- dprintf(logfd, "\n\nNO LOGINS: System going down %s\n\n", when);
+ if (tm) {
+ strftime(when, sizeof(when), "at %H:%M %Z", tm);
+ dprintf(logfd,
+ "\n\nNO LOGINS: System going down %s\n\n", when);
+ } else
+ dprintf(logfd,
+ "\n\nNO LOGINS: System going in %lld minute%s\n\n",
+ (long long)(timeleft / 60),
+ (timeleft > 60) ? "s" : "");
close(logfd);
}
}
}
now = (time_t)time(NULL);
#if defined(HAVE_STRFTIME) && defined(HAVE_LOCALTIME_R)
- if(log_time_asc && strftime(tmbuf, sizeof(tmbuf), "%b %d %H:%M:%S",
- localtime_r(&now, &tm))%(sizeof(tmbuf)) != 0) {
+ if(log_time_asc && localtime_r(&now, &tm) && strftime(tmbuf,
+ sizeof(tmbuf), "%b %d %H:%M:%S", &tm)%(sizeof(tmbuf)) != 0) {
/* %sizeof buf!=0 because old strftime returned max on error */
fprintf(logfile, "%s %s[%d:%x] %s: %s\n", tmbuf,
ident, (int)getpid(), tid?*tid:0, type, message);