Skip to contentSkip to conversation

Fix NULL pointer warning

PATCH In review Mimi Zohar 2 participants 2 messages Jul 13, 2021 Keys-trusted

lore
Share & tools
lore

Mimi Zohar

author maintainer
#0 lore raw

PATCH 1/1 Fix NULL pointer warning

Static analysis reported an "invalid operation involving NULL pointer" warning. Although the code properly exits the loop without ever using the variable, test the pointer isn't NULL before incrementing it.

Fixes 80d3fda6083f ("ima-evm-utils: Check for tsspcrread in runtime")
---
 src/utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/utils.c +2 -1
index ce2cc285a930..fd9b4a84189f 100644
@@ -77,7 +77,8 @@ int get_cmd_path(const char *prog_name, char *buf, size_t buf_len)
 		if (buf_len - size > ret && file_exist(buf))
 			return 0;
 
-		start = end + 1;
+		if (end != NULL)
+			start = end + 1;
 
 	} while (end != NULL);
 
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Mimi Zohar

Static analysis reported an "invalid operation involving NULL pointer" warning. Although the code properly exits the loop without ever using the variable, test the pointer isn't NULL before incrementing it.

Fixes 80d3fda6083f ("ima-evm-utils: Check for tsspcrread in runtime")
---
  src/utils.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

-lakshmi

Quoted 16 lines
src/utils.c +2 -1
index ce2cc285a930..fd9b4a84189f 100644
@@ -77,7 +77,8 @@ int get_cmd_path(const char *prog_name, char *buf, size_t buf_len)
  		if (buf_len - size > ret && file_exist(buf))
  			return 0;
 
-		start = end + 1;
+		if (end != NULL)
+			start = end + 1;
 
  	} while (end != NULL);