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

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