1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 07:27:59 -08:00

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
This commit is contained in:
florian 2024-05-09 08:35:03 +00:00
parent d30853d157
commit 94c8de5490
3 changed files with 12 additions and 6 deletions

View File

@ -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'),

View File

@ -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')

View File

@ -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",