summaryrefslogtreecommitdiffstats
path: root/meta/recipes-bsp/grub/files/0030-commands-hashsum-Fix-a-memory-leak.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-bsp/grub/files/0030-commands-hashsum-Fix-a-memory-leak.patch')
-rw-r--r--meta/recipes-bsp/grub/files/0030-commands-hashsum-Fix-a-memory-leak.patch56
1 files changed, 56 insertions, 0 deletions
diff --git a/meta/recipes-bsp/grub/files/0030-commands-hashsum-Fix-a-memory-leak.patch b/meta/recipes-bsp/grub/files/0030-commands-hashsum-Fix-a-memory-leak.patch
new file mode 100644
index 0000000000..e34a19e12c
--- /dev/null
+++ b/meta/recipes-bsp/grub/files/0030-commands-hashsum-Fix-a-memory-leak.patch
@@ -0,0 +1,56 @@
1From b136fa14d26d1833ffcb852f86e65da5960cfb99 Mon Sep 17 00:00:00 2001
2From: Chris Coulson <chris.coulson@canonical.com>
3Date: Tue, 1 Dec 2020 23:41:24 +0000
4Subject: [PATCH] commands/hashsum: Fix a memory leak
5
6check_list() uses grub_file_getline(), which allocates a buffer.
7If the hash list file contains invalid lines, the function leaks
8this buffer when it returns an error.
9
10Fixes: CID 176635
11
12Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
13Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14
15Upstream-Status: Backport [https://git.savannah.gnu.org/cgit/grub.git/commit/?id=8b6f528e52e18b7a69f90b8dc3671d7b1147d9f3]
16Signed-off-by: Marta Rybczynska <marta.rybczynska@huawei.com>
17---
18 grub-core/commands/hashsum.c | 15 ++++++++++++---
19 1 file changed, 12 insertions(+), 3 deletions(-)
20
21diff --git a/grub-core/commands/hashsum.c b/grub-core/commands/hashsum.c
22index 456ba90..b8a22b0 100644
23--- a/grub-core/commands/hashsum.c
24+++ b/grub-core/commands/hashsum.c
25@@ -128,11 +128,17 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
26 high = hextoval (*p++);
27 low = hextoval (*p++);
28 if (high < 0 || low < 0)
29- return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
30+ {
31+ grub_free (buf);
32+ return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
33+ }
34 expected[i] = (high << 4) | low;
35 }
36 if ((p[0] != ' ' && p[0] != '\t') || (p[1] != ' ' && p[1] != '\t'))
37- return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
38+ {
39+ grub_free (buf);
40+ return grub_error (GRUB_ERR_BAD_FILE_TYPE, "invalid hash list");
41+ }
42 p += 2;
43 if (prefix)
44 {
45@@ -140,7 +146,10 @@ check_list (const gcry_md_spec_t *hash, const char *hashfilename,
46
47 filename = grub_xasprintf ("%s/%s", prefix, p);
48 if (!filename)
49- return grub_errno;
50+ {
51+ grub_free (buf);
52+ return grub_errno;
53+ }
54 file = grub_file_open (filename, GRUB_FILE_TYPE_TO_HASH
55 | (!uncompress ? GRUB_FILE_TYPE_NO_DECOMPRESS
56 : GRUB_FILE_TYPE_NONE));