Skip to contentSkip to conversation

blsuki: Fix grub_errno leakage in blsuki_is_default_entry()

PATCH In review Michael Chang via Grub-devel 2 participants 2 messages Nov 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 blsuki: Fix grub_errno leakage in blsuki_is_default_entry()

The grub_strtol() call in blsuki_is_default_entry() can set grub_errno to either GRUB_ERR_BAD_NUMBER or GRUB_ERR_OUT_OF_RANGE if the input string is invalid or out of range.

This errno value is currently left uncleared, which can lead to unexpected behavior in subsequent functions that rely on checking current state of grub_errno.

Clear grub_errno unconditionally when grub_strtol() reports error so that we can plug the leak.

---
 grub-core/commands/blsuki.c | 4 ++++
 1 file changed, 4 insertions(+)
grub-core/commands/blsuki.c +4 -0
index 21d767f05..c41172d3a 100644
@@ -1510,6 +1510,10 @@ blsuki_is_default_entry (const char *def_entry, grub_blsuki_entry_t *entry, int
     return true;
 
   def_idx = grub_strtol (def_entry, &def_entry_end, 0);
+
+  /* Clear grub_errno so we can plug the leak */
+  grub_errno = GRUB_ERR_NONE;
+
   if (*def_entry_end != '\0' || def_idx < 0 || def_idx > GRUB_INT_MAX)
     return false;
 
Signature · 7 lines
2.51.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v4 1/1
#1 lore raw
Quoted 8 lines · Michael Chang via Grub-devel

The grub_strtol() call in blsuki_is_default_entry() can set grub_errno to either GRUB_ERR_BAD_NUMBER or GRUB_ERR_OUT_OF_RANGE if the input string is invalid or out of range.

This errno value is currently left uncleared, which can lead to unexpected behavior in subsequent functions that rely on checking current state of grub_errno.

Quoted 7 lines

Clear grub_errno unconditionally when grub_strtol() reports error so that we can plug the leak.

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel