Re: [PATCH] blsuki: Fix grub_errno leakage in blsuki_is_default_entry()

Michael Lawnick via Grub-devel <[email protected]>
Newsgroups org.gnu.grub-devel
Message-ID <[email protected]>

Am 10.11.2025 um 08:38 schrieb Michael Chang via Grub-devel:
> The grub_strtol() call in blsuki_is_default_entry() can set grub_errno
> to GRUB_ERR_BAD_NUMBER if the input string cannot be converted into any
> valid digits.
> 
> This errno value is currently left uncleared, which can lead to
> unexpected behavior in subsequent logic that tests the result of a
> function by checking grub_errno.
> 
> Clear grub_errno and return false when GRUB_ERR_BAD_NUMBER is set, as
> this specific error should be ignored in this context.
> 
> Signed-off-by: Michael Chang <[email protected]>
> ---
>  grub-core/commands/blsuki.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/grub-core/commands/blsuki.c b/grub-core/commands/blsuki.c
> index 21d767f05..df25b6fbc 100644
> --- a/grub-core/commands/blsuki.c
> +++ b/grub-core/commands/blsuki.c
> @@ -1510,6 +1510,12 @@ 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);
> +  if (grub_errno == GRUB_ERR_BAD_NUMBER)
> +    {
> +      grub_errno = GRUB_ERR_NONE;
> +      return false;
> +    }
> +
>    if (*def_entry_end != '\0' || def_idx < 0 || def_idx > GRUB_INT_MAX)
>      return false;
>  
This way you'll clear a possible previous GRUB_ERR_BAD_NUMBER
Shouldn't it be this way:
     return true;

+  old_err = grub_errno;
+  grub_errno = GRUB_ERR_NONE;
   def_idx = grub_strtol (def_entry, &def_entry_end, 0);
+  if (grub_errno == GRUB_ERR_BAD_NUMBER)
+    {
+      grub_errno = old_err;
+      return false;
+    }
+    grub_errno = old_err;
+
   if (*def_entry_end != '\0' || def_idx < 0 || def_idx > GRUB_INT_MAX)
     return false;

JMTC
KR Michael

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.