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

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

Commit Message

Colin King July 4, 2019, 4:29 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 a null
pointer check to avoid this.

Addresses-Coverity: ("Uninitialized pointer read")
Fixes: 2a377d8ec8c3 ("acpi: method: add _PTC test")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/method/method.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Alex Hung July 4, 2019, 5:42 p.m. UTC | #1
On 2019-07-04 10:29 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 a null
> pointer check to avoid this.
> 
> Addresses-Coverity: ("Uninitialized pointer read")
> Fixes: 2a377d8ec8c3 ("acpi: method: add _PTC test")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/method/method.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
> index 67a54465..37f6068d 100644
> --- a/src/acpi/method/method.c
> +++ b/src/acpi/method/method.c
> @@ -2538,12 +2538,12 @@ static void method_test_PTC_return(
>  		return;
>  
>  	for (i = 0; i < obj->Package.Count; i++) {
> -		ACPI_RESOURCE *resource;
> +		ACPI_RESOURCE *resource = NULL;
>  		ACPI_STATUS   status;
>  		ACPI_OBJECT *element_buf = &obj->Package.Elements[i];
>  
>  		status = AcpiBufferToResource(element_buf->Buffer.Pointer, element_buf->Buffer.Length, &resource);
> -		if (ACPI_FAILURE(status)) {
> +		if (ACPI_FAILURE(status) || !resource) {
>  			failed = true;
>  			fwts_failed(fw, LOG_LEVEL_HIGH,
>  				"Method_PTCBadElement",
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
ivanhu July 24, 2019, 6:41 a.m. UTC | #2
On 7/5/19 12:29 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 a null
> pointer check to avoid this.
> 
> Addresses-Coverity: ("Uninitialized pointer read")
> Fixes: 2a377d8ec8c3 ("acpi: method: add _PTC test")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/method/method.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/acpi/method/method.c b/src/acpi/method/method.c
> index 67a54465..37f6068d 100644
> --- a/src/acpi/method/method.c
> +++ b/src/acpi/method/method.c
> @@ -2538,12 +2538,12 @@ static void method_test_PTC_return(
>   		return;
>   
>   	for (i = 0; i < obj->Package.Count; i++) {
> -		ACPI_RESOURCE *resource;
> +		ACPI_RESOURCE *resource = NULL;
>   		ACPI_STATUS   status;
>   		ACPI_OBJECT *element_buf = &obj->Package.Elements[i];
>   
>   		status = AcpiBufferToResource(element_buf->Buffer.Pointer, element_buf->Buffer.Length, &resource);
> -		if (ACPI_FAILURE(status)) {
> +		if (ACPI_FAILURE(status) || !resource) {
>   			failed = true;
>   			fwts_failed(fw, LOG_LEVEL_HIGH,
>   				"Method_PTCBadElement",
> 

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 67a54465..37f6068d 100644
--- a/src/acpi/method/method.c
+++ b/src/acpi/method/method.c
@@ -2538,12 +2538,12 @@  static void method_test_PTC_return(
 		return;
 
 	for (i = 0; i < obj->Package.Count; i++) {
-		ACPI_RESOURCE *resource;
+		ACPI_RESOURCE *resource = NULL;
 		ACPI_STATUS   status;
 		ACPI_OBJECT *element_buf = &obj->Package.Elements[i];
 
 		status = AcpiBufferToResource(element_buf->Buffer.Pointer, element_buf->Buffer.Length, &resource);
-		if (ACPI_FAILURE(status)) {
+		if (ACPI_FAILURE(status) || !resource) {
 			failed = true;
 			fwts_failed(fw, LOG_LEVEL_HIGH,
 				"Method_PTCBadElement",