From 6d7977a7cc789ad51b6dc37538e7a68612352465 Mon Sep 17 00:00:00 2001 From: Kazutaka YOKOTA Date: Fri, 7 Mar 1997 10:54:19 +0000 Subject: [PATCH] Made sure the string formated by strftime() is properly null-terminated. Should go to RELENG_2_1 and RELENG_2_2. Reviewed by guido@freebsd.org. --- usr.bin/w/pr_time.c | 3 ++- usr.bin/w/w.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/usr.bin/w/pr_time.c b/usr.bin/w/pr_time.c index 6faf6db10ecd..c48f6a7cf738 100644 --- a/usr.bin/w/pr_time.c +++ b/usr.bin/w/pr_time.c @@ -76,7 +76,8 @@ pr_attime(started, now) (void)strcpy(fmt, __CONCAT("%l:%", "M%p")); } - (void)strftime(buf, sizeof(buf), fmt, tp); + (void)strftime(buf, sizeof(buf) - 1, fmt, tp); + buf[sizeof(buf) - 1] = '\0'; (void)printf("%s", buf); } diff --git a/usr.bin/w/w.c b/usr.bin/w/w.c index c615430c04d6..f02799717b61 100644 --- a/usr.bin/w/w.c +++ b/usr.bin/w/w.c @@ -377,8 +377,9 @@ pr_header(nowp, nusers) * SCCS forces the string manipulation below, as it replaces * %, M, and % in a character string with the file name. */ - (void)strftime(buf, sizeof(buf), + (void)strftime(buf, sizeof(buf) - 1, __CONCAT("%l:%","M%p"), localtime(nowp)); + buf[sizeof(buf) - 1] = '\0'; (void)printf("%s ", buf); /*