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

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