fwts_modprobe: fix potential null pointer dereference
diff mbox series

Message ID 20190610101742.27518-1-colin.king@canonical.com
State Accepted
Headers show
Series
  • fwts_modprobe: fix potential null pointer dereference
Related show

Commit Message

Colin King June 10, 2019, 10:17 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The null pointer check is currently incorrect; if ptr is null then
we currently have a null pointer dereference. The check should be
for a null ptr rather rather than the contents of the object being
pointed to being non-zero.

Addresses-Coverity: ("Dereference null pointer")
Fixes: cbf322756c13 ("src/lib: add module probing helper functions")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_modprobe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alex Hung June 10, 2019, 8:28 p.m. UTC | #1
On 2019-06-10 3:17 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The null pointer check is currently incorrect; if ptr is null then
> we currently have a null pointer dereference. The check should be
> for a null ptr rather rather than the contents of the object being
> pointed to being non-zero.
> 
> Addresses-Coverity: ("Dereference null pointer")
> Fixes: cbf322756c13 ("src/lib: add module probing helper functions")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_modprobe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/lib/src/fwts_modprobe.c b/src/lib/src/fwts_modprobe.c
> index 05871f2c..a05a581f 100644
> --- a/src/lib/src/fwts_modprobe.c
> +++ b/src/lib/src/fwts_modprobe.c
> @@ -131,7 +131,7 @@ int fwts_module_loaded(fwts_framework *fw, const char *module, bool *loaded)
>  	while (fgets(buffer, sizeof(buffer) - 1, fp) != NULL) {
>  		char *ptr = strchr(buffer, ' ');
>  
> -		if (*ptr)
> +		if (ptr)
>  			*ptr = '\0';
>  
>  		if (!strcmp(buffer, module)) {
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
ivanhu June 11, 2019, 5:43 a.m. UTC | #2
On 6/10/19 6:17 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> The null pointer check is currently incorrect; if ptr is null then
> we currently have a null pointer dereference. The check should be
> for a null ptr rather rather than the contents of the object being
> pointed to being non-zero.
>
> Addresses-Coverity: ("Dereference null pointer")
> Fixes: cbf322756c13 ("src/lib: add module probing helper functions")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_modprobe.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_modprobe.c b/src/lib/src/fwts_modprobe.c
> index 05871f2c..a05a581f 100644
> --- a/src/lib/src/fwts_modprobe.c
> +++ b/src/lib/src/fwts_modprobe.c
> @@ -131,7 +131,7 @@ int fwts_module_loaded(fwts_framework *fw, const char *module, bool *loaded)
>  	while (fgets(buffer, sizeof(buffer) - 1, fp) != NULL) {
>  		char *ptr = strchr(buffer, ' ');
>  
> -		if (*ptr)
> +		if (ptr)
>  			*ptr = '\0';
>  
>  		if (!strcmp(buffer, module)) {


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

Patch
diff mbox series

diff --git a/src/lib/src/fwts_modprobe.c b/src/lib/src/fwts_modprobe.c
index 05871f2c..a05a581f 100644
--- a/src/lib/src/fwts_modprobe.c
+++ b/src/lib/src/fwts_modprobe.c
@@ -131,7 +131,7 @@  int fwts_module_loaded(fwts_framework *fw, const char *module, bool *loaded)
 	while (fgets(buffer, sizeof(buffer) - 1, fp) != NULL) {
 		char *ptr = strchr(buffer, ' ');
 
-		if (*ptr)
+		if (ptr)
 			*ptr = '\0';
 
 		if (!strcmp(buffer, module)) {