On Mon, Nov 10, 2025 at 2:38 AM, Michael Chang <[email protected]> wrote: > 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.
grub_strtol() can also set grub_errno to GRUB_ERR_OUT_OF_RANGE. Would it make sense to check for that as well? We do return false if def_idx is negative or larger than GRUB_INT_MAX, but I don't know if we would want to sustain GRUB_ERR_OUT_OF_RANGE in grub_errno past this function should the "def_entry" passed into this function contain a bad value that causes grub_strtol() to give an error. Alec Brown > > 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; > > -- > 2.51.1 > > > _______________________________________________ > Grub-devel mailing list > [email protected] > https://urldefense.com/v3/__https://lists.gnu.org/mailman/listinfo/grub- > devel__;!!ACWV5N9M2RV99hQ!PT07VdaZpBxwaIforN0iXRL1OG2vC6xOV2SQ6cgn5eVQvHxGFpEtx3c9eNW_ApT4iml6Fnoj > FNjVxarvCu1C$ _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
