Blame SOURCES/0011-Don-t-leak-from-one-extractTitle-call.patch

24fce8
From 38d8178482ea7dabf7c4ab8c2973faa2b469e9c7 Mon Sep 17 00:00:00 2001
24fce8
From: Peter Jones <pjones@redhat.com>
24fce8
Date: Thu, 2 Jul 2015 16:26:59 -0400
24fce8
Subject: [PATCH 11/55] Don't leak from one extractTitle() call.
24fce8
24fce8
Found by coverity.
24fce8
24fce8
Signed-off-by: Peter Jones <pjones@redhat.com>
24fce8
---
24fce8
 grubby.c | 27 +++++++++++++++++----------
24fce8
 1 file changed, 17 insertions(+), 10 deletions(-)
24fce8
24fce8
diff --git a/grubby.c b/grubby.c
24fce8
index 0bb486967bf..70477ba14ee 100644
24fce8
--- a/grubby.c
24fce8
+++ b/grubby.c
24fce8
@@ -1510,13 +1510,14 @@ static struct grubConfig * readConfig(const char * inName,
24fce8
     return cfg;
24fce8
 }
24fce8
 
24fce8
-static void writeDefault(FILE * out, char * indent, 
24fce8
+static void writeDefault(FILE * out, char * indent,
24fce8
 			 char * separator, struct grubConfig * cfg) {
24fce8
     struct singleEntry * entry;
24fce8
     struct singleLine * line;
24fce8
     int i;
24fce8
 
24fce8
-    if (!cfg->defaultImage && cfg->flags == GRUB_CONFIG_NO_DEFAULT) return;
24fce8
+    if (!cfg->defaultImage && cfg->flags == GRUB_CONFIG_NO_DEFAULT)
24fce8
+	return;
24fce8
 
24fce8
     if (cfg->defaultImage == DEFAULT_SAVED)
24fce8
 	fprintf(out, "%sdefault%ssaved\n", indent, separator);
24fce8
@@ -1540,34 +1541,40 @@ static void writeDefault(FILE * out, char * indent,
24fce8
 	        fprintf(out, "%sset default=\"%d\"\n", indent,
24fce8
 			cfg->defaultImage);
24fce8
 	    } else {
24fce8
-		fprintf(out, "%sdefault%s%d\n", indent, separator, 
24fce8
+		fprintf(out, "%sdefault%s%d\n", indent, separator,
24fce8
 			cfg->defaultImage);
24fce8
 	    }
24fce8
 	} else {
24fce8
 	    int image = cfg->defaultImage;
24fce8
 
24fce8
 	    entry = cfg->entries;
24fce8
-	    while (entry && entry->skip) entry = entry->next;
24fce8
+	    while (entry && entry->skip)
24fce8
+		entry = entry->next;
24fce8
 
24fce8
 	    i = 0;
24fce8
 	    while (entry && i < image) {
24fce8
 		entry = entry->next;
24fce8
 
24fce8
-		while (entry && entry->skip) entry = entry->next;
24fce8
+		while (entry && entry->skip)
24fce8
+		    entry = entry->next;
24fce8
 		i++;
24fce8
 	    }
24fce8
 
24fce8
-	    if (!entry) return;
24fce8
+	    if (!entry)
24fce8
+		return;
24fce8
 
24fce8
 	    line = getLineByType(LT_TITLE, entry->lines);
24fce8
 
24fce8
 	    if (line && line->numElements >= 2)
24fce8
-		fprintf(out, "%sdefault%s%s\n", indent, separator, 
24fce8
+		fprintf(out, "%sdefault%s%s\n", indent, separator,
24fce8
 			line->elements[1].item);
24fce8
-            else if (line && (line->numElements == 1) && 
24fce8
+            else if (line && (line->numElements == 1) &&
24fce8
                      cfg->cfi->titleBracketed) {
24fce8
-		fprintf(out, "%sdefault%s%s\n", indent, separator, 
24fce8
-                        extractTitle(cfg, line));
24fce8
+		char *title = extractTitle(cfg, line);
24fce8
+		if (title) {
24fce8
+		    fprintf(out, "%sdefault%s%s\n", indent, separator, title);
24fce8
+		    free(title);
24fce8
+		}
24fce8
             }
24fce8
 	}
24fce8
     }
24fce8
-- 
24fce8
2.17.1
24fce8