From 1be53cb47e5e94f5efecaf6ebc55311493343183 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <thomas@t-8ch.de>
Date: Tue, 26 Dec 2023 11:18:00 +0100
Subject: [PATCH] cal: avoid out of bound write
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
---
 misc-utils/cal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/misc-utils/cal.c b/misc-utils/cal.c
index 693449dbc..e6f4a6e4f 100644
--- a/misc-utils/cal.c
+++ b/misc-utils/cal.c
@@ -692,9 +692,9 @@ static void headers_init(struct cal_control *ctl)
 	for (i = 0; i < DAYS_IN_WEEK; i++) {
 		size_t space_left;
 
-		if (i)
-			strcat(cur_dh++, " ");
 		space_left = sizeof(day_headings) - (cur_dh - day_headings);
+		if (i && space_left)
+			strncat(cur_dh++, " ", space_left--);
 
 		if (space_left <= (ctl->day_width - 1))
 			break;
-- 
2.33.0

