Blame SOURCES/0177-strauss-fix-off-by-one-error-in-strauss-array-access.patch

024872
From 968789d5426442ac43b96eabd65f3e5c0c141e62 Mon Sep 17 00:00:00 2001
024872
From: Eugene Syromyatnikov <evgsyr@gmail.com>
024872
Date: Tue, 28 Jun 2022 16:47:56 +0200
024872
Subject: [PATCH] strauss: fix off-by-one error in strauss array access
024872
024872
It has to be limited with strauss_lines - 1, not strauss_lines.
024872
Reported by covscan:
024872
024872
    Error: OVERRUN (CWE-119):
024872
    strace-5.18/src/strauss.c:380: cond_at_least: Checking "4UL + i < 37UL"
024872
    implies that "i" is at least 33 on the false branch.
024872
    strace-5.18/src/strauss.c:380: overrun-local: Overrunning array "strauss"
024872
    of 37 8-byte elements at element index 37 (byte offset 303) using index
024872
    "(4UL + i < 37UL) ? 4UL + i : 37UL" (which evaluates to 37).
024872
024872
* src/strauss.c (print_totd): Limit strauss array accesses to
024872
strauss_lines - 1 instead of strauss_lines.
024872
---
024872
 src/strauss.c | 6 +++---
024872
 1 file changed, 3 insertions(+), 3 deletions(-)
024872
024872
diff --git a/src/strauss.c b/src/strauss.c
024872
index 98af183..b22ab6a 100644
024872
--- a/src/strauss.c
024872
+++ b/src/strauss.c
024872
@@ -373,16 +373,16 @@ print_totd(void)
024872
 			tip_left[MIN(i + 1, ARRAY_SIZE(tip_left) - 1)],
024872
 			w, w, tips_tricks_tweaks[id][i] ?: "",
024872
 			tip_right[MIN(i + 1, ARRAY_SIZE(tip_right) - 1)],
024872
-			strauss[MIN(3 + i, strauss_lines)]);
024872
+			strauss[MIN(3 + i, strauss_lines - 1)]);
024872
 	}
024872
 	fprintf(stderr, "%s%s\n",
024872
-		tip_bottom, strauss[MIN(3 + i, strauss_lines)]);
024872
+		tip_bottom, strauss[MIN(3 + i, strauss_lines - 1)]);
024872
 	do {
024872
 		fprintf(stderr, "%*s%*s%*s%s\n",
024872
 			(int) strlen(tip_left[0]), "",
024872
 			w, "",
024872
 			(int) strlen(tip_right[0]), "",
024872
-			strauss[MIN(4 + i, strauss_lines)]);
024872
+			strauss[MIN(4 + i, strauss_lines - 1)]);
024872
 	} while ((show_tips == TIPS_FULL) && (4 + ++i < strauss_lines));
024872
 
024872
 	printed = true;
024872
-- 
024872
2.1.4
024872