Re: [PATCH] efiemu/loadcore: Add grub_calloc failure check

2025-11-27 Thread Avnish Chouhan

On 2025-11-27 12:36, [email protected] wrote:

Message: 3
Date: Thu, 27 Nov 2025 10:06:33 +0300
From: "Vladimir 'phcoder' Serbinenko" 
To: The development of GNU GRUB 
Subject: Re: [PATCH] efiemu/loadcore: Add grub_calloc failure check
Message-ID:

Content-Type: text/plain; charset="utf-8"

grub_calloc already sets error variables. So you need to return 
grub_errno

and not call grub_error

Regards
Vladimir 'phcoder' Serbinenko



Hi Vladimir,

Sure, I'll change it to as suggested.
Thank you!

Regards,
Avnish Chouhan

___
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] efiemu/loadcore: Add grub_calloc failure check

2025-11-26 Thread Vladimir 'phcoder' Serbinenko
grub_calloc already sets error variables. So you need to return grub_errno
and not call grub_error

Regards
Vladimir 'phcoder' Serbinenko

Le mer. 26 nov. 2025, 09:52, Avnish Chouhan  a écrit :

> Adding a failure check in grub_calloc(). If grub_calloc fails,
> (e.g., due to memory allocation failure), it returns NULL.
> Then, using grub_efiemu_elfsyms (which would be NULL)
> later will result in a null pointer dereference,
> and can cause an undefined behavior.
>
> Signed-off-by: Avnish Chouhan 
> ---
>  grub-core/efiemu/loadcore.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/grub-core/efiemu/loadcore.c b/grub-core/efiemu/loadcore.c
> index 2b92462..5a6d244 100644
> --- a/grub-core/efiemu/loadcore.c
> +++ b/grub-core/efiemu/loadcore.c
> @@ -203,6 +203,9 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e)
>grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *)
>  grub_calloc (grub_efiemu_nelfsyms, sizeof (struct
> grub_efiemu_elf_sym));
>
> +  if (grub_efiemu_elfsyms == NULL)
> +return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
> +
>/* Relocators */
>for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
> i < e->e_shnum;
> --
> 2.46.0
>
>
> ___
> Grub-devel mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
___
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] efiemu/loadcore: Add grub_calloc failure check

2025-11-26 Thread Sudhakar Kuppusamy


> On 26 Nov 2025, at 12:21 PM, Avnish Chouhan  wrote:
> 
> Adding a failure check in grub_calloc(). If grub_calloc fails,
> (e.g., due to memory allocation failure), it returns NULL. 
> Then, using grub_efiemu_elfsyms (which would be NULL)
> later will result in a null pointer dereference,
> and can cause an undefined behavior.
> 
> Signed-off-by: Avnish Chouhan 

Reviewed-by: Sudhakar Kuppusamy 

Thanks,
Sudhakar  
> ---
> grub-core/efiemu/loadcore.c | 3 +++
> 1 file changed, 3 insertions(+)
> 
> diff --git a/grub-core/efiemu/loadcore.c b/grub-core/efiemu/loadcore.c
> index 2b92462..5a6d244 100644
> --- a/grub-core/efiemu/loadcore.c
> +++ b/grub-core/efiemu/loadcore.c
> @@ -203,6 +203,9 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e)
>   grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *)
> grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym));
> 
> +  if (grub_efiemu_elfsyms == NULL)
> +return grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
> +
>   /* Relocators */
>   for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
>i < e->e_shnum;
> -- 
> 2.46.0
> 
> 
> ___
> Grub-devel mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/grub-devel


___
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel