On Mon, Jan 12, 2026 at 11:20:14PM +0530, Avnish Chouhan wrote: > Add a check for invalid partition number. grub_strtoul() may fail > in several scenarios like invalid input, overflow, etc. Lack of > proper check may lead to unexpected failures in the code further. > > Signed-off-by: Avnish Chouhan <[email protected]>
Reviewed-by: Daniel Kiper <[email protected]> > --- > grub-core/kern/ieee1275/openfw.c | 17 +++++++++++++++-- > 1 file changed, 15 insertions(+), 2 deletions(-) > > diff --git a/grub-core/kern/ieee1275/openfw.c > b/grub-core/kern/ieee1275/openfw.c > index 3b492dd..f8ae515 100644 > --- a/grub-core/kern/ieee1275/openfw.c > +++ b/grub-core/kern/ieee1275/openfw.c > @@ -512,7 +512,20 @@ grub_ieee1275_encode_devname (const char *path) > } > if (partition && partition[0]) > { > - unsigned int partno = grub_strtoul (partition, 0, 0); > + unsigned long partno; > + char *endptr; > + > + partno = grub_strtoul (partition, &endptr, 0); > + grub_errno = GRUB_ERR_NONE; > + if (*endptr != '\0' || partno > 65535 || > + (partno == 0 && ! grub_ieee1275_test_flag > (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS))) > + { > + grub_free (partition); > + grub_free (device); > + grub_free (encoding); > + grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid partition number")); > + return NULL; > + } > > *optr++ = ','; > > @@ -520,7 +533,7 @@ grub_ieee1275_encode_devname (const char *path) > /* GRUB partition 1 is OF partition 0. */ > partno++; > > - grub_snprintf (optr, sizeof ("XXXXXXXXXXXX"), "%d", partno); > + grub_snprintf (optr, sizeof ("XXXXXXXXXXXX"), "%zu", partno); Huh! I have just realized that I misread the code and made wrong suggestion. Of course "%zu" should be "%lu". I will fix this for you. Sorry for the noise... Daniel _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
