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

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