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

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