Skip to contentSkip to conversation

kern/file: Fix error handling in grub_file_open()

PATCH In review Steve McIntyre 2 participants 2 messages Dec 6, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kern/file: Fix error handling in grub_file_open()

grub_file_open() calls grub_file_get_device_name(), but doesn't check the return. Instead, it checks if grub_errno is set.

However, nothing initialises grub_errno here when grub_file_open() starts. This means that trying to open one file that doesn't exist and then trying to open another file that does will (incorrectly) also fail to open that second file.

Let's fix that.

---
 grub-core/kern/file.c | 3 +++
 1 file changed, 3 insertions(+)
grub-core/kern/file.c +3 -0
index 8d48fd50d..668b149c3 100644
@@ -66,6 +66,9 @@ grub_file_open (const char *name, enum grub_file_type type)
   const char *file_name;
   grub_file_filter_id_t filter;
 
+  /* Reset grub_errno before we start */
+  grub_errno = GRUB_ERR_NONE;
+
   device_name = grub_file_get_device_name (name);
   if (grub_errno)
     goto fail;
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Steve McIntyre

grub_file_open() calls grub_file_get_device_name(), but doesn't check the return. Instead, it checks if grub_errno is set.

However, nothing initialises grub_errno here when grub_file_open() starts. This means that trying to open one file that doesn't exist and then trying to open another file that does will (incorrectly) also fail to open that second file.

Let's fix that.

Daniel