[libcamera-devel,v2] libcamera: ipa_module: prevent uninitialised access

Message ID 20190801113850.4920-1-kieran.bingham@ideasonboard.com
State Accepted
Commit 9ecc60e10c96d1abd7d68899831e3ab143a16520
Headers show
Series
  • [libcamera-devel,v2] libcamera: ipa_module: prevent uninitialised access
Related show

Commit Message

Kieran Bingham Aug. 1, 2019, 11:38 a.m. UTC
The IPAModule::loadIPAModuleInfo() function includes a *data pointer
which is used as a null-pointer comparison in the error path with a
conditional statement of "if (ret || !data)".

The data variable is not initialised, and a single error path evaluates
this as "if (true || uninitialised)".

Whilst this error path does not incorrectly utilise the uninitialised
data, as the ret evaluates to true already, it does leave a statement
which includes an uninitialised variable.

Help the static analysers by initialising the data variable when it is
defined.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

---
v2:
 - s/NULL/nullptr/
 - Fix spelling in commit-message

 src/libcamera/ipa_module.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Laurent Pinchart Aug. 1, 2019, 2:32 p.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Thu, Aug 01, 2019 at 12:38:50PM +0100, Kieran Bingham wrote:
> The IPAModule::loadIPAModuleInfo() function includes a *data pointer
> which is used as a null-pointer comparison in the error path with a
> conditional statement of "if (ret || !data)".
> 
> The data variable is not initialised, and a single error path evaluates
> this as "if (true || uninitialised)".
> 
> Whilst this error path does not incorrectly utilise the uninitialised
> data, as the ret evaluates to true already, it does leave a statement
> which includes an uninitialised variable.
> 
> Help the static analysers by initialising the data variable when it is
> defined.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
> v2:
>  - s/NULL/nullptr/
>  - Fix spelling in commit-message
> 
>  src/libcamera/ipa_module.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp
> index 003611625214..99d308efd47b 100644
> --- a/src/libcamera/ipa_module.cpp
> +++ b/src/libcamera/ipa_module.cpp
> @@ -291,7 +291,7 @@ int IPAModule::loadIPAModuleInfo()
>  		return ret;
>  	}
>  
> -	void *data;
> +	void *data = nullptr;
>  	size_t dataSize;
>  	void *map;
>  	size_t soSize;

Patch

diff --git a/src/libcamera/ipa_module.cpp b/src/libcamera/ipa_module.cpp
index 003611625214..99d308efd47b 100644
--- a/src/libcamera/ipa_module.cpp
+++ b/src/libcamera/ipa_module.cpp
@@ -291,7 +291,7 @@  int IPAModule::loadIPAModuleInfo()
 		return ret;
 	}
 
-	void *data;
+	void *data = nullptr;
 	size_t dataSize;
 	void *map;
 	size_t soSize;