nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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