From: florian Date: Thu, 9 May 2024 08:35:03 +0000 (+0000) Subject: ctime(3) and ctime_r(3) can fail when timestamps are way off. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=94c8de549078a156f9fd3b5860c3a954e0098074;p=openbsd 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 --- 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 @@ -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 @@ -730,6 +730,7 @@ initcon(struct con *cp, int fd, struct sockaddr *sa) NI_NUMERICHOST); if (error) strlcpy(cp->addr, "", 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",