On Tue, 8 Jul 2025 at 13:08, Heinrich Schuchardt
<heinrich.schucha...@canonical.com> wrote:
>
> Avoid copying to NULL if out of memory.
>
> Fixes: 3c08df58cc43 ("lib: efi_loader: efi_memory.c: add efi_realloc() for 
> realloc memory")
> Addresses-Coverity-ID: 569499: Null pointer dereferences (NULL_RETURNS)
> Signed-off-by: Heinrich Schuchardt <heinrich.schucha...@canonical.com>
> ---


Reviewed-by: Ilias Apalodimas <ilias.apalodi...@linaro.org>

>  lib/efi_loader/efi_memory.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
> index 6dfc698a247..b77c2f980cc 100644
> --- a/lib/efi_loader/efi_memory.c
> +++ b/lib/efi_loader/efi_memory.c
> @@ -714,6 +714,8 @@ efi_status_t efi_realloc(void **ptr, size_t size)
>                 sizeof(struct efi_pool_allocation);
>
>         new_ptr = efi_alloc(size);
> +       if (!new_ptr)
> +               return EFI_OUT_OF_RESOURCES;
>
>         /* copy old data to new alloced buffer */
>         memcpy(new_ptr, *ptr, min(size, old_size));
> --
> 2.48.1
>

Reply via email to