85cfe6d
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
85cfe6d
From: Steve McIntyre <steve@einval.com>
85cfe6d
Date: Tue, 6 Dec 2022 01:45:11 +0000
85cfe6d
Subject: [PATCH] kern/file: Fix error handling in grub_file_open()
85cfe6d
85cfe6d
grub_file_open() calls grub_file_get_device_name(), but doesn't check
85cfe6d
the return. Instead, it checks if grub_errno is set.
85cfe6d
85cfe6d
However, nothing initialises grub_errno here when grub_file_open()
85cfe6d
starts. This means that trying to open one file that doesn't exist and
85cfe6d
then trying to open another file that does will (incorrectly) also
85cfe6d
fail to open that second file.
85cfe6d
85cfe6d
Let's fix that.
85cfe6d
85cfe6d
Signed-off-by: Steve McIntyre <steve@einval.com>
85cfe6d
---
85cfe6d
 grub-core/kern/file.c | 3 +++
85cfe6d
 1 file changed, 3 insertions(+)
85cfe6d
85cfe6d
diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c
85cfe6d
index 58454458c4..5b58f45cfd 100644
85cfe6d
--- a/grub-core/kern/file.c
85cfe6d
+++ b/grub-core/kern/file.c
85cfe6d
@@ -66,6 +66,9 @@ grub_file_open (const char *name, enum grub_file_type type)
85cfe6d
   const char *file_name;
85cfe6d
   grub_file_filter_id_t filter;
85cfe6d
 
85cfe6d
+  /* Reset grub_errno before we start */
85cfe6d
+  grub_errno = GRUB_ERR_NONE;
85cfe6d
+
85cfe6d
   device_name = grub_file_get_device_name (name);
85cfe6d
   if (grub_errno)
85cfe6d
     goto fail;