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

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