From 54ff6aff58a59ad50a77483786b209da25e1ed73 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 11 Jul 2024 14:15:44 +0200 Subject: [PATCH] cal: make sure day_in_week() does not overrun array size [coverity scan] It's very theoretical, but protect against this possibility. Signed-off-by: Karel Zak --- misc-utils/cal.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/misc-utils/cal.c b/misc-utils/cal.c index 89bce4051..1af95124c 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -1175,6 +1175,9 @@ static int day_in_week(const struct cal_control *ctl, int day, static const int reform[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; static const int old[] = { 5, 1, 0, 3, 5, 1, 3, 6, 2, 4, 0, 2 }; + if (month > 0 && month - 1 >= (int) ARRAY_SIZE(old)) + month = ARRAY_SIZE(old); /* for sure */ + if (year != ctl->reform_year + 1) year -= month < MARCH; else -- 2.47.3