Blame SOURCES/0414-commands-hashsum-Fix-a-memory-leak.patch

468bd4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
468bd4
From: Chris Coulson <chris.coulson@canonical.com>
468bd4
Date: Tue, 1 Dec 2020 23:41:24 +0000
468bd4
Subject: [PATCH] commands/hashsum: Fix a memory leak
468bd4
468bd4
check_list() uses grub_file_getline(), which allocates a buffer.
468bd4
If the hash list file contains invalid lines, the function leaks
468bd4
this buffer when it returns an error.
468bd4
468bd4
Fixes: CID 176635
468bd4
468bd4
Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
468bd4
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
468bd4
---
468bd4
 grub-core/commands/hashsum.c | 15 ++++++++++++---
468bd4
 1 file changed, 12 insertions(+), 3 deletions(-)
468bd4
468bd4
diff --git a/grub-core/commands/hashsum.c b/grub-core/commands/hashsum.c
09e3cc
index 456ba908b..b8a22b0c8 100644
468bd4
--- a/grub-core/commands/hashsum.c
468bd4
+++ b/grub-core/commands/hashsum.c
468bd4
@@ -128,11 +128,17 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
468bd4
 	  high = hextoval (*p++);
468bd4
 	  low = hextoval (*p++);
468bd4
 	  if (high < 0 || low < 0)
468bd4
-	    return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
468bd4
+	    {
468bd4
+	      grub_free (buf);
468bd4
+	      return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
468bd4
+	    }
468bd4
 	  expected[i] = (high << 4) | low;
468bd4
 	}
468bd4
       if ((p[0] != ' ' && p[0] != '\t') || (p[1] != ' ' && p[1] != '\t'))
468bd4
-	return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
468bd4
+	{
468bd4
+	  grub_free (buf);
468bd4
+	  return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
468bd4
+	}
468bd4
       p += 2;
468bd4
       if (prefix)
468bd4
 	{
468bd4
@@ -140,7 +146,10 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
468bd4
 	  
468bd4
 	  filename = grub_xasprintf ("%s/%s", prefix, p);
468bd4
 	  if (!filename)
468bd4
-	    return grub_errno;
468bd4
+	    {
468bd4
+	      grub_free (buf);
468bd4
+	      return grub_errno;
468bd4
+	    }
468bd4
 	  file = grub_file_open (filename, GRUB_FILE_TYPE_TO_HASH
468bd4
 				 | (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
468bd4
 				    : GRUB_FILE_TYPE_NONE));