> On 28 Oct 2025, at 10:02 PM, Avnish Chouhan <[email protected]> wrote:
> 
> Adding a failure check after calling grub_malloc() as it can lead to
> undefined behavior. If the allocation fails and returns NULL, subsequent
> dereferencing or writing to the pointer will likely result in a runtime
> error such as a segmentation fault.
> 
> Signed-off-by: Avnish Chouhan <[email protected]>

Reviewed-by: Sudhakar Kuppusamy <[email protected]>

Thanks,
Sudhakar  
> ---
> grub-core/mmap/mmap.c | 3 +++
> 1 file changed, 3 insertions(+)
> 
> diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c
> index c8c8312..8f03b77 100644
> --- a/grub-core/mmap/mmap.c
> +++ b/grub-core/mmap/mmap.c
> @@ -242,6 +242,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void 
> *hook_data)
>  else
>    {
>      struct mm_list *n = grub_malloc (sizeof (*n));
> +              if (n == NULL)
> +                return grub_errno;
> +
>      n->val = ctx.scanline_events[i].memtype;
>      n->present = 1;
>      n->next = present[ctx.scanline_events[i].priority].next;
> -- 
> 2.47.1
> 
> 
> _______________________________________________
> 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

Reply via email to