nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0513-kern-file-Do-not-leak-device_name-on-error-in-grub_f.patch

0ccc47
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
0ccc47
From: Daniel Axtens <dja@axtens.net>
0ccc47
Date: Fri, 25 Jun 2021 02:19:05 +1000
0ccc47
Subject: [PATCH] kern/file: Do not leak device_name on error in
0ccc47
 grub_file_open()
0ccc47
0ccc47
If we have an error in grub_file_open() before we free device_name, we
0ccc47
will leak it.
0ccc47
0ccc47
Free device_name in the error path and null out the pointer in the good
0ccc47
path once we free it there.
0ccc47
0ccc47
Signed-off-by: Daniel Axtens <dja@axtens.net>
0ccc47
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
0ccc47
(cherry picked from commit 1499a5068839fa37cb77ecef4b5bdacbd1ed12ea)
0ccc47
(cherry picked from commit 2ec50b289d8b24922433439533113087f111f110)
0ccc47
(cherry picked from commit 17c36ae88d7d6040cabc01cd4a21e71ff4731668)
0ccc47
---
0ccc47
 grub-core/kern/file.c | 2 ++
0ccc47
 1 file changed, 2 insertions(+)
0ccc47
0ccc47
diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c
0ccc47
index 2efc31da94..f062fc21e7 100644
0ccc47
--- a/grub-core/kern/file.c
0ccc47
+++ b/grub-core/kern/file.c
0ccc47
@@ -81,6 +81,7 @@ grub_file_open (const char *name, enum grub_file_type type)
0ccc47
 
0ccc47
   device = grub_device_open (device_name);
0ccc47
   grub_free (device_name);
0ccc47
+  device_name = NULL;
0ccc47
   if (! device)
0ccc47
     goto fail;
0ccc47
 
0ccc47
@@ -135,6 +136,7 @@ grub_file_open (const char *name, enum grub_file_type type)
0ccc47
   return file;
0ccc47
 
0ccc47
  fail:
0ccc47
+  grub_free (device_name);
0ccc47
   if (device)
0ccc47
     grub_device_close (device);
0ccc47