1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-21 23:18:00 -08:00

gmtime(3) / locatime(3) can fail when timestamps are way off.

Add missing error checks to all calls under libexec/

Input & OK millert
This commit is contained in:
florian 2024-04-28 16:42:53 +00:00
parent 327caad7a1
commit 73fe6daa50
4 changed files with 41 additions and 27 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ftpcmd.y,v 1.74 2023/03/08 04:43:05 guenther Exp $ */
/* $OpenBSD: ftpcmd.y,v 1.75 2024/04/28 16:42:53 florian Exp $ */
/* $NetBSD: ftpcmd.y,v 1.7 1996/04/08 19:03:11 jtc Exp $ */
/*
@ -613,6 +613,11 @@ cmd
} else {
struct tm *t;
t = gmtime(&stbuf.st_mtime);
if (t == NULL) {
/* invalid time, use epoch */
stbuf.st_mtime = 0;
t = gmtime(&stbuf.st_mtime);
}
reply(213,
"%04d%02d%02d%02d%02d%02d",
1900 + t->tm_year,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.54 2019/06/28 13:32:53 deraadt Exp $ */
/* $OpenBSD: main.c,v 1.55 2024/04/28 16:42:53 florian Exp $ */
/*-
* Copyright (c) 1980, 1993
@ -562,10 +562,12 @@ putf(char *cp)
break;
case 'd': {
(void)time(&t);
(void)strftime(db, sizeof(db),
"%l:%M%p on %A, %d %B %Y", localtime(&t));
xputs(db);
struct tm *tm;
time(&t);
if ((tm = localtime(&t)) != NULL)
if (strftime(db, sizeof(db),
"%l:%M%p on %A, %d %B %Y", tm) != 0)
xputs(db);
break;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mib.c,v 1.7 2023/11/21 08:49:08 martijn Exp $ */
/* $OpenBSD: mib.c,v 1.8 2024/04/28 16:42:53 florian Exp $ */
/*
* Copyright (c) 2022 Martijn van Duren <martijn@openbsd.org>
@ -296,27 +296,29 @@ mib_hrsystemdate(struct agentx_varbind *vb)
int tzoffset;
unsigned short year;
memset(s, 0, sizeof(s));
(void)time(&now);
ptm = localtime(&now);
year = htons(ptm->tm_year + 1900);
memcpy(s, &year, 2);
s[2] = ptm->tm_mon + 1;
s[3] = ptm->tm_mday;
s[4] = ptm->tm_hour;
s[5] = ptm->tm_min;
s[6] = ptm->tm_sec;
s[7] = 0;
if (ptm != NULL) {
year = htons(ptm->tm_year + 1900);
memcpy(s, &year, 2);
s[2] = ptm->tm_mon + 1;
s[3] = ptm->tm_mday;
s[4] = ptm->tm_hour;
s[5] = ptm->tm_min;
s[6] = ptm->tm_sec;
s[7] = 0;
tzoffset = ptm->tm_gmtoff;
if (tzoffset < 0)
s[8] = '-';
else
s[8] = '+';
s[9] = abs(tzoffset) / 3600;
s[10] = (abs(tzoffset) - (s[9] * 3600)) / 60;
tzoffset = ptm->tm_gmtoff;
if (tzoffset < 0)
s[8] = '-';
else
s[8] = '+';
s[9] = abs(tzoffset) / 3600;
s[10] = (abs(tzoffset) - (s[9] * 3600)) / 60;
}
agentx_varbind_nstring(vb, s, sizeof(s));
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: announce.c,v 1.25 2019/06/28 13:32:53 deraadt Exp $ */
/* $OpenBSD: announce.c,v 1.26 2024/04/28 16:42:53 florian Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
@ -102,9 +102,14 @@ print_mesg(FILE *tf, CTL_MSG *request, char *remote_machine)
sizes[i] = strlen(line_buf[i]);
max_size = max(max_size, sizes[i]);
i++;
(void)snprintf(line_buf[i], N_CHARS,
"Message from Talk_Daemon@%s at %d:%02d ...",
hostname, localclock->tm_hour , localclock->tm_min );
if (localclock) {
(void)snprintf(line_buf[i], N_CHARS,
"Message from Talk_Daemon@%s at %d:%02d ...",
hostname, localclock->tm_hour , localclock->tm_min );
} else {
(void)snprintf(line_buf[i], N_CHARS,
"Message from Talk_Daemon@%s ...", hostname);
}
sizes[i] = strlen(line_buf[i]);
max_size = max(max_size, sizes[i]);
i++;