nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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