Skip to contentSkip to conversation

cg_read_strcmp: Fix null pointer dereference

PATCH In review Gaurav Singh 2 participants 3 messages Jul 25, 2020 – Jul 26, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cg_read_strcmp: Fix null pointer dereference

Passing NULL in strcmp will cause a segmentation fault. Fix this by returning -1 if expected is NULL pointer.

---
 tools/testing/selftests/cgroup/cgroup_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/cgroup/cgroup_util.c +1 -1
index 8a637ca7d73a..05853b0b8831 100644
@@ -106,7 +106,7 @@ int cg_read_strcmp(const char *cgroup, const char *control,
 
 	/* Handle the case of comparing against empty string */
 	if (!expected)
-		size = 32;
+		return -1;
 	else
 		size = strlen(expected) + 1;
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 2 lines · Gaurav Singh

Passing NULL in strcmp will cause a segmentation fault. Fix this by returning -1 if expected is NULL pointer.

Did you actually encounter this while running the tests?

#2 lore raw

PATCH 1/1 cg_read_strcmp: Fix null pointer dereference

In reply to Gaurav Singh

Haven't reproduced this issue. This PR is does a minor code cleanup.

---
 tools/testing/selftests/cgroup/cgroup_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/cgroup/cgroup_util.c +1 -1
index 8a637ca7d73a..05853b0b8831 100644
@@ -106,7 +106,7 @@ int cg_read_strcmp(const char *cgroup, const char *control,
 
 	/* Handle the case of comparing against empty string */
 	if (!expected)
-		size = 32;
+		return -1;
 	else
 		size = strlen(expected) + 1;
 
Signature · 1 line
2.17.1