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