summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2024-05-09 08:35:04 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2024-05-09 08:35:04 +0000
commit9243a6b7a514d95e7618fdee4bad66710b0fff13 (patch)
treea6f745f108d178a5ae34d25c0ec9913d08280e5b
parent12b2798abb74a39631e4324e04db889d67509f24 (diff)
ctime(3) and ctime_r(3) can fail when timestamps are way off.
Add missing error checks to all calls under libexec/ Input kettenis, millert OK millert
-rw-r--r--libexec/ftpd/ftpd.c8
-rw-r--r--libexec/mail.local/mail.local.c7
-rw-r--r--libexec/spamd/spamd.c3
3 files changed, 12 insertions, 6 deletions
diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c
index 810933525da..e77a4efcc27 100644
--- a/libexec/ftpd/ftpd.c
+++ b/libexec/ftpd/ftpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftpd.c,v 1.233 2023/03/08 04:43:05 guenther Exp $ */
+/* $OpenBSD: ftpd.c,v 1.234 2024/05/09 08:35:03 florian Exp $ */
/* $NetBSD: ftpd.c,v 1.15 1995/06/03 22:46:47 mycroft Exp $ */
/*
@@ -2739,7 +2739,10 @@ logxfer(const char *name, off_t size, time_t start)
int len;
if ((statfd >= 0) && (getcwd(dir, sizeof(dir)) != NULL)) {
+ char *cnow;
+
time(&now);
+ cnow = ctime(&now);
vpw = malloc(strlen(guest ? guestpw : pw->pw_name) * 4 + 1);
if (vpw == NULL)
@@ -2755,7 +2758,8 @@ logxfer(const char *name, off_t size, time_t start)
len = snprintf(buf, sizeof(buf),
"%.24s %lld %s %lld %s %c %s %c %c %s ftp %d %s %s\n",
- ctime(&now), (long long)(now - start + (now == start)),
+ cnow ? cnow : "?",
+ (long long)(now - start + (now == start)),
vremotehost, (long long)size, vpath,
((type == TYPE_A) ? 'a' : 'b'), "*" /* none yet */,
'o', ((guest) ? 'a' : 'r'),
diff --git a/libexec/mail.local/mail.local.c b/libexec/mail.local/mail.local.c
index 7d0dfb4abb1..8289dad5d7d 100644
--- a/libexec/mail.local/mail.local.c
+++ b/libexec/mail.local/mail.local.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mail.local.c,v 1.42 2023/06/05 08:07:18 op Exp $ */
+/* $OpenBSD: mail.local.c,v 1.43 2024/05/09 08:35:03 florian Exp $ */
/*-
* Copyright (c) 1996-1998 Theo de Raadt <deraadt@theos.com>
@@ -112,7 +112,7 @@ storemail(char *from)
FILE *fp = NULL;
time_t tval;
int fd, eline = 1;
- char *tbuf, *line = NULL;
+ char *tbuf, *line = NULL, *cnow;
size_t linesize = 0;
ssize_t linelen;
@@ -124,7 +124,8 @@ storemail(char *from)
free(tbuf);
(void)time(&tval);
- (void)fprintf(fp, "From %s %s", from, ctime(&tval));
+ cnow = ctime(&tval);
+ (void)fprintf(fp, "From %s %s", from, cnow ? cnow : "?\n");
while ((linelen = getline(&line, &linesize, stdin)) != -1) {
if (line[linelen - 1] == '\n')
diff --git a/libexec/spamd/spamd.c b/libexec/spamd/spamd.c
index 1be4c4b5527..53fbc72979e 100644
--- a/libexec/spamd/spamd.c
+++ b/libexec/spamd/spamd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: spamd.c,v 1.162 2024/04/01 21:09:44 millert Exp $ */
+/* $OpenBSD: spamd.c,v 1.163 2024/05/09 08:35:03 florian Exp $ */
/*
* Copyright (c) 2015 Henning Brauer <henning@openbsd.org>
@@ -730,6 +730,7 @@ initcon(struct con *cp, int fd, struct sockaddr *sa)
NI_NUMERICHOST);
if (error)
strlcpy(cp->addr, "<unknown>", sizeof(cp->addr));
+ memset(ctimebuf, 0, sizeof(ctimebuf));
ctime_r(&t, ctimebuf);
ctimebuf[sizeof(ctimebuf) - 2] = '\0'; /* nuke newline */
snprintf(cp->obuf, cp->osize, "220 %s ESMTP %s; %s\r\n",