public inbox for grub-devel@gnu.org
 help / color / mirror / Atom feed
From: Avnish Chouhan <avnish@linux.ibm.com>
To: Daniel Kiper <daniel.kiper@oracle.com>
Cc: grub-devel@gnu.org
Subject: Re: [PATCH v3] ieee1275 : Add a check for invalid partition number
Date: Mon, 12 Jan 2026 19:54:55 +0530	[thread overview]
Message-ID: <bf4f9918c618f41dce7fffc3b2bbff4f@linux.ibm.com> (raw)
In-Reply-To: <aWT77rzbICiPaLYU@tomti.i.net-space.pl>

On 2026-01-12 19:19, Daniel Kiper wrote:
> On Mon, Jan 12, 2026 at 06:59:00PM +0530, Avnish Chouhan wrote:
>> Adding a check for invalid partition number. grub_strtoul() can fail
> 
> s/Adding/Add/
> s/can/may/
> 
>> in several scenarios like invalid input, overflow, etc will result in
> 
> s/etc/etc./
> 
>> an invalid partition number which could lead to an undefined behavior.
> 
> s/will result in an invalid partition number which could lead to an
> undefined behavior.
>  /Lack of proper check may lead to unexpected failures in the code 
> further./
> 

Hi Daniel,
Thank you for the review!

I'll change these as suggested.

>> Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
>> ---
>>  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);
>> +      char *endptr;
>> +
>> +      unsigned long partno = grub_strtoul (partition, &endptr, 0);
>> +      grub_errno = GRUB_ERR_NONE;
> 
> I would do this
> 
>   unsigned long partno;
>   char *endptr;
> 
>   partno = grub_strtoul (partition, &endptr, 0);
>   grub_errno = GRUB_ERR_NONE;

Sure. I'll change like this.

> 
>> +      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"), "%lu", partno);
> 
> Why is this change part of the patch? Even if it is valid it is 
> logically
> different thing. And I would use "%zu" instead...

This we need due to change from "unsigned int partno" to "unsigned long 
partno". In present code, partno is unsigned int, and we were using the 
same (though in the present code, it is wrong. It must be '%u' instead 
of '%d' anyway). Reason we didn't change this in earlier patch versions.

We'll change it to zu as suggested!

Regards,
Avnish Chouhan

> 
> Daniel

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  reply	other threads:[~2026-01-12 14:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-12 13:29 [PATCH v3] ieee1275 : Add a check for invalid partition number Avnish Chouhan
2026-01-12 13:49 ` Daniel Kiper via Grub-devel
2026-01-12 14:24   ` Avnish Chouhan [this message]
2026-01-12 14:22 ` Nicholas Vinson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf4f9918c618f41dce7fffc3b2bbff4f@linux.ibm.com \
    --to=avnish@linux.ibm.com \
    --cc=daniel.kiper@oracle.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox