Blame SOURCES/0037-Fix-findTemplate-index-logic-1285601.patch

cca0c4
From 46843e71656264d98ceda79985e5d341a8d58aa7 Mon Sep 17 00:00:00 2001
cca0c4
From: Robert Marshall <rmarshall@redhat.com>
cca0c4
Date: Thu, 22 Dec 2016 17:52:14 -0500
cca0c4
Subject: [PATCH 37/55] Fix findTemplate index logic (#1285601)
cca0c4
cca0c4
The fallback case where findTemplate has to look for the first entry
cca0c4
contained a logic flaw that could return an incorrect index. This
cca0c4
discovered index should be reduced by one for each boot entry that will
cca0c4
be skipped in the final output. The flaw occurred because the index
cca0c4
variable was used for the loop upper bound at the same time as it was
cca0c4
being decremented within the actual loop body. The loop would thus fail
cca0c4
to examine a number of boot entries equal to the total number of
cca0c4
iterations the loop performed.
cca0c4
cca0c4
Related: rhbz#1285601
cca0c4
---
cca0c4
 grubby.c | 7 +++++--
cca0c4
 1 file changed, 5 insertions(+), 2 deletions(-)
cca0c4
cca0c4
diff --git a/grubby.c b/grubby.c
cca0c4
index fcca6364887..692c351ccb6 100644
cca0c4
--- a/grubby.c
cca0c4
+++ b/grubby.c
cca0c4
@@ -2436,8 +2436,11 @@ struct singleEntry *findTemplate(struct grubConfig *cfg, const char *prefix,
cca0c4
 	index = 0;
cca0c4
 	while ((entry = findEntryByIndex(cfg, index))) {
cca0c4
 		if (suitableImage(entry, prefix, skipRemoved, flags)) {
cca0c4
-			int j;
cca0c4
-			for (j = 0; j < index; j++) {
cca0c4
+			int j, unmodifiedIndex;
cca0c4
+
cca0c4
+			unmodifiedIndex = index;
cca0c4
+
cca0c4
+			for (j = 0; j < unmodifiedIndex; j++) {
cca0c4
 				entry2 = findEntryByIndex(cfg, j);
cca0c4
 				if (entry2->skip)
cca0c4
 					index--;
cca0c4
-- 
cca0c4
2.17.1
cca0c4