nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0240-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
(cherry picked from commit 2ec50b289d8b24922433439533113087f111f110)
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
e28c09
index e19aea3e51..ed69fc0f0f 100644
e28c09
--- a/grub-core/kern/file.c
e28c09
+++ b/grub-core/kern/file.c
e28c09
@@ -81,6 +81,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
 
e28c09
@@ -135,6 +136,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