public inbox for grub-devel@gnu.org
 help / color / mirror / Atom feed
From: Avnish Chouhan <avnish@linux.ibm.com>
To: sridharm@linux.ibm.com
Cc: grub-devel@gnu.org, daniel.kiper@oracle.com, phcoder@gmail.com,
	sudhakar@linux.ibm.com, stefanb@linux.ibm.com,
	nayna@linux.ibm.com, ssrish@linux.ibm.com,
	alec.r.brown@oracle.com
Subject: Re: [PATCH v2] normal/menu_entry: Add grub_calloc failure check
Date: Tue, 02 Dec 2025 23:03:12 +0530	[thread overview]
Message-ID: <cfa67f5874480badb9833ec318234316@linux.ibm.com> (raw)
In-Reply-To: <mailman.4226.1764658927.1191.grub-devel@gnu.org>

On 2025-12-02 12:32, grub-devel-request@gnu.org wrote:
> Message: 3
> Date: Tue,  2 Dec 2025 12:31:48 +0530
> From: Sridhar Markonda <sridharm@linux.ibm.com>
> To: grub-devel@gnu.org
> Cc: daniel.kiper@oracle.com, phcoder@gmail.com,
> 	sudhakar@linux.ibm.com, stefanb@linux.ibm.com, nayna@linux.ibm.com,
> 	sridharm@linux.ibm.com, ssrish@linux.ibm.com
> Subject: [PATCH v2] normal/menu_entry: Add grub_calloc failure check
> Message-ID: <20251202070148.35202-1-sridharm@linux.ibm.com>
> 
> Add a NULL check to prevent failure from grub_calloc in update_screen.
> This stops possible NULL pointer dereference and avoids unexpected 
> behavior.
> 
> Signed-off-by: Sridhar Markonda <sridharm@linux.ibm.com>
> ---
>  grub-core/normal/menu_entry.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/grub-core/normal/menu_entry.c 
> b/grub-core/normal/menu_entry.c
> index 8b0d17e3f..411b0ad53 100644
> --- a/grub-core/normal/menu_entry.c
> +++ b/grub-core/normal/menu_entry.c
> @@ -295,8 +295,12 @@ update_screen (struct screen *screen, struct
> per_term_screen *term_screen,
> 
>  	  pos = linep->pos + (term_screen - screen->terms);
> 
> -	  if (!*pos)
> -	    *pos = grub_calloc (linep->len + 1, sizeof (**pos));
> +	  if (*pos == NULL)
> +	    {
> +	      *pos = grub_calloc (linep->len + 1, sizeof (**pos));
> +	      if (*pos == NULL)
> +		return;

Hi Sridhar,
Thank you so much for the patch!

In my opinion, returning due to grub_calloc failure might not be a good 
idea here!

To me, it seems grub_print_ucs4_menu() and its corresponding functions 
which uses 'pos' as a last argument handles NULL properly. So returning 
based on this argument being NULL might not be a good idea. There are 
other parts of the code in GRUB where grub_print_ucs4_menu() has been 
called with this last argument as 0.

Regards,
Avnish Chouhan


> +	    }
> 
>  	  if (i == region_start || linep == screen->lines + screen->line
>  	      || (i > region_start && mode == ALL_LINES))
> --
> 2.47.3
> 
> 
> 
> 
> ------------------------------
> 
> Subject: Digest Footer
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 
> 
> ------------------------------
> 
> End of Grub-devel Digest, Vol 262, Issue 5
> ******************************************

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

       reply	other threads:[~2025-12-02 17:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.4226.1764658927.1191.grub-devel@gnu.org>
2025-12-02 17:33 ` Avnish Chouhan [this message]
2025-12-20 13:14   ` [PATCH v2] normal/menu_entry: Add grub_calloc failure check Daniel Kiper
2025-12-02  7:01 Sridhar Markonda

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=cfa67f5874480badb9833ec318234316@linux.ibm.com \
    --to=avnish@linux.ibm.com \
    --cc=alec.r.brown@oracle.com \
    --cc=daniel.kiper@oracle.com \
    --cc=grub-devel@gnu.org \
    --cc=nayna@linux.ibm.com \
    --cc=phcoder@gmail.com \
    --cc=sridharm@linux.ibm.com \
    --cc=ssrish@linux.ibm.com \
    --cc=stefanb@linux.ibm.com \
    --cc=sudhakar@linux.ibm.com \
    /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