acpi: method: add null pointer sanity checks on resource
diff mbox series

Message ID 20190704162147.5528-1-colin.king@canonical.com
State Accepted
Headers show
Series
  • acpi: method: add null pointer sanity checks on resource
Related show

Commit Message

Colin Ian King July 4, 2019, 4:21 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The pointer resource could possibly be null or even a garbage
value when it is dereferenced causing a segmentation fault, so
be extra vigilent, nullify it to start with and add some null
pointer checks to avoid this.

Addresses-Coverity: ("Uninitialized pointer read")
Fixes: 6768f6248e95 ("acpi: method: refine _EVT test")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/method/method.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Alex Hung July 4, 2019, 5:42 p.m. UTC | #1
On 2019-07-04 10:21 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The pointer resource could possibly be null or even a garbage
> value when it is dereferenced causing a segmentation fault, so
> be extra vigilent, nullify it to start with and add some null
> pointer checks to avoid this.
> 
> Addresses-Coverity: ("Uninitialized pointer read")
> Fixes: 6768f6248e95 ("acpi: method: refine _EVT test")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/method/method.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
> index 787e3438..67a54465 100644
> --- a/src/acpi/method/method.c
> +++ b/src/acpi/method/method.c
> @@ -620,7 +620,7 @@ static void method_test_EVT_return (
>  	ACPI_OBJECT *obj,
>  	void *private)
>  {
> -	ACPI_RESOURCE *resource;
> +	ACPI_RESOURCE *resource = NULL;
>  	ACPI_STATUS   status;
>  
>  	FWTS_UNUSED(private);
> @@ -629,7 +629,7 @@ static void method_test_EVT_return (
>  		return;
>  
>  	status = AcpiBufferToResource(obj->Buffer.Pointer, obj->Buffer.Length, &resource);
> -	if (ACPI_FAILURE(status))
> +	if (ACPI_FAILURE(status) || !resource)
>  		return;
>  
>  	do {
> @@ -643,7 +643,7 @@ static void method_test_EVT_return (
>  				check_evt_event(fw, &resource->Data.Gpio);
>  
>  		resource = ACPI_NEXT_RESOURCE(resource);
> -	} while (resource->Type != ACPI_RESOURCE_TYPE_END_TAG);
> +	} while (resource && resource->Type != ACPI_RESOURCE_TYPE_END_TAG);
>  }
>  
>  static int method_test_EVT(fwts_framework *fw)
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu July 24, 2019, 6:32 a.m. UTC | #2
On 7/5/19 12:21 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The pointer resource could possibly be null or even a garbage
> value when it is dereferenced causing a segmentation fault, so
> be extra vigilent, nullify it to start with and add some null
> pointer checks to avoid this.
> 
> Addresses-Coverity: ("Uninitialized pointer read")
> Fixes: 6768f6248e95 ("acpi: method: refine _EVT test")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/method/method.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
> index 787e3438..67a54465 100644
> --- a/src/acpi/method/method.c
> +++ b/src/acpi/method/method.c
> @@ -620,7 +620,7 @@ static void method_test_EVT_return (
>   	ACPI_OBJECT *obj,
>   	void *private)
>   {
> -	ACPI_RESOURCE *resource;
> +	ACPI_RESOURCE *resource = NULL;
>   	ACPI_STATUS   status;
>   
>   	FWTS_UNUSED(private);
> @@ -629,7 +629,7 @@ static void method_test_EVT_return (
>   		return;
>   
>   	status = AcpiBufferToResource(obj->Buffer.Pointer, obj->Buffer.Length, &resource);
> -	if (ACPI_FAILURE(status))
> +	if (ACPI_FAILURE(status) || !resource)
>   		return;
>   
>   	do {
> @@ -643,7 +643,7 @@ static void method_test_EVT_return (
>   				check_evt_event(fw, &resource->Data.Gpio);
>   
>   		resource = ACPI_NEXT_RESOURCE(resource);
> -	} while (resource->Type != ACPI_RESOURCE_TYPE_END_TAG);
> +	} while (resource && resource->Type != ACPI_RESOURCE_TYPE_END_TAG);
>   }
>   
>   static int method_test_EVT(fwts_framework *fw)
> 

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

Patch
diff mbox series

diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
index 787e3438..67a54465 100644
--- a/src/acpi/method/method.c
+++ b/src/acpi/method/method.c
@@ -620,7 +620,7 @@  static void method_test_EVT_return (
 	ACPI_OBJECT *obj,
 	void *private)
 {
-	ACPI_RESOURCE *resource;
+	ACPI_RESOURCE *resource = NULL;
 	ACPI_STATUS   status;
 
 	FWTS_UNUSED(private);
@@ -629,7 +629,7 @@  static void method_test_EVT_return (
 		return;
 
 	status = AcpiBufferToResource(obj->Buffer.Pointer, obj->Buffer.Length, &resource);
-	if (ACPI_FAILURE(status))
+	if (ACPI_FAILURE(status) || !resource)
 		return;
 
 	do {
@@ -643,7 +643,7 @@  static void method_test_EVT_return (
 				check_evt_event(fw, &resource->Data.Gpio);
 
 		resource = ACPI_NEXT_RESOURCE(resource);
-	} while (resource->Type != ACPI_RESOURCE_TYPE_END_TAG);
+	} while (resource && resource->Type != ACPI_RESOURCE_TYPE_END_TAG);
 }
 
 static int method_test_EVT(fwts_framework *fw)