Re: [PATCH] ieee1275 : Add a check for invalid partition number
Alec Brown via Grub-devel <[email protected]> Mon, 1 Dec 2025 22:31:30 +0000
| Newsgroups | org.gnu.grub-devel |
|---|---|
| Message-ID | <CH3PR10MB6834D62E7514C11A64DAB3A7BCDBA@CH3PR10MB6834.namprd10.prod.outlook.com> |
On Mon, Dec 1, 2025 at 1:52 AM, Avnish Chouhan <[email protected]> wrote: > Adding a check for invalid partition number. grub_strtoul() can fail > in several scenarios like invalid input, overflow, etc will result in > an invalid partition number which could lead to an undefined behavior. > > Signed-off-by: Avnish Chouhan <[email protected]> > --- > grub-core/kern/ieee1275/openfw.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/grub-core/kern/ieee1275/openfw.c b/grub-core/kern/ieee1275/openfw.c > index 3b492dd..29bdb72 100644 > --- a/grub-core/kern/ieee1275/openfw.c > +++ b/grub-core/kern/ieee1275/openfw.c > @@ -512,8 +512,18 @@ grub_ieee1275_encode_devname (const char *path) > } > if (partition && partition[0]) > { > + grub_errno = GRUB_ERR_NONE; > unsigned int partno = grub_strtoul (partition, 0, 0); > > + if (grub_errno != GRUB_ERR_NONE) This check isn't reliable. Please see how grub_strtoul() is handled in commit ac8a37dda (net/http: Allow use of non-standard TCP/IP ports). Even if it is reverted, the code around grub_strtoul() is fully correct. Alec Brown > + { > + grub_free (partition); > + grub_free (device); > + grub_free (encoding); > + grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid partition number")); > + return NULL; > + } > + > *optr++ = ','; > > if (grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS)) > -- > 2.52.0 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel