debugger: check for memory allocation failure on object Elements
diff mbox series

Message ID 20191127130754.37321-1-colin.king@canonical.com
State Accepted
Headers show
Series
  • debugger: check for memory allocation failure on object Elements
Related show

Commit Message

Colin Ian King Nov. 27, 2019, 1:07 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The allocation of Elements may fail, so add a null check to
avoid any null pointer dereference faulting.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpica/source/components/debugger/dbconvert.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Alex Hung Dec. 5, 2019, 3:22 a.m. UTC | #1
On 2019-11-27 6:07 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The allocation of Elements may fail, so add a null check to
> avoid any null pointer dereference faulting.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpica/source/components/debugger/dbconvert.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/src/acpica/source/components/debugger/dbconvert.c b/src/acpica/source/components/debugger/dbconvert.c
> index 6b58bf5f..a9014b8f 100644
> --- a/src/acpica/source/components/debugger/dbconvert.c
> +++ b/src/acpica/source/components/debugger/dbconvert.c
> @@ -354,6 +354,10 @@ AcpiDbConvertToPackage (
>   
>       Elements = ACPI_ALLOCATE_ZEROED (
>           DB_DEFAULT_PKG_ELEMENTS * sizeof (ACPI_OBJECT));
> +    if (!Elements)
> +    {
> +        return (AE_NO_MEMORY);
> +    }
>   
>       This = String;
>       for (i = 0; i < (DB_DEFAULT_PKG_ELEMENTS - 1); i++)
> 
Acked-by: Alex Hung <alex.hung@canonical.com>
ivanhu Dec. 6, 2019, 2:16 a.m. UTC | #2
On 11/27/19 9:07 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The allocation of Elements may fail, so add a null check to
> avoid any null pointer dereference faulting.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpica/source/components/debugger/dbconvert.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/src/acpica/source/components/debugger/dbconvert.c b/src/acpica/source/components/debugger/dbconvert.c
> index 6b58bf5f..a9014b8f 100644
> --- a/src/acpica/source/components/debugger/dbconvert.c
> +++ b/src/acpica/source/components/debugger/dbconvert.c
> @@ -354,6 +354,10 @@ AcpiDbConvertToPackage (
>  
>      Elements = ACPI_ALLOCATE_ZEROED (
>          DB_DEFAULT_PKG_ELEMENTS * sizeof (ACPI_OBJECT));
> +    if (!Elements)
> +    {
> +        return (AE_NO_MEMORY);
> +    }
>  
>      This = String;
>      for (i = 0; i < (DB_DEFAULT_PKG_ELEMENTS - 1); i++)
> 

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch
diff mbox series

diff --git a/src/acpica/source/components/debugger/dbconvert.c b/src/acpica/source/components/debugger/dbconvert.c
index 6b58bf5f..a9014b8f 100644
--- a/src/acpica/source/components/debugger/dbconvert.c
+++ b/src/acpica/source/components/debugger/dbconvert.c
@@ -354,6 +354,10 @@  AcpiDbConvertToPackage (
 
     Elements = ACPI_ALLOCATE_ZEROED (
         DB_DEFAULT_PKG_ELEMENTS * sizeof (ACPI_OBJECT));
+    if (!Elements)
+    {
+        return (AE_NO_MEMORY);
+    }
 
     This = String;
     for (i = 0; i < (DB_DEFAULT_PKG_ELEMENTS - 1); i++)