From 0151441e15d04505ce3f12b0b80d3e31ea08f56e Mon Sep 17 00:00:00 2001 From: Qualys Security Advisory Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] w: Check return values in print_logintime(). --- w.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/w.c b/w.c index 7bb5babc..2bee3968 100644 --- a/w.c +++ b/w.c @@ -283,10 +283,8 @@ static time_t idletime(const char *restrict const tty) } /* 7 character formatted login time */ - static void print_logintime(time_t logt, FILE * fout) { - /* Abbreviated of weekday can be longer than 3 characters, * see for instance hu_HU. Using 16 is few bytes more than * enough. */ @@ -296,23 +294,29 @@ static void print_logintime(time_t logt, FILE * fout) int today; curt = time(NULL); + if (curt == (time_t)(-1)) goto error; curtm = localtime(&curt); + if (!curtm) goto error; /* localtime returns a pointer to static memory */ today = curtm->tm_yday; logtm = localtime(&logt); + if (!logtm) goto error; if (curt - logt > 12 * 60 * 60 && logtm->tm_yday != today) { if (curt - logt > 6 * 24 * 60 * 60) { - strftime(time_str, sizeof(time_str), "%b", logtm); + if (!strftime(time_str, sizeof(time_str), "%b", logtm)) goto error; fprintf(fout, " %02d%3s%02d", logtm->tm_mday, time_str, logtm->tm_year % 100); } else { - strftime(time_str, sizeof(time_str), "%a", logtm); + if (!strftime(time_str, sizeof(time_str), "%a", logtm)) goto error; fprintf(fout, " %3s%02d ", time_str, logtm->tm_hour); } } else { fprintf(fout, " %02d:%02d ", logtm->tm_hour, logtm->tm_min); } + return; +error: + fprintf(fout, " ???????"); } /*