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

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