Linux-kselftest Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] [cgroup/testing] cg_read_strcmp: Fix null pointer dereference
@ 2020-07-25 18:14 Gaurav Singh
  2020-07-25 20:23 ` Chris Down
  2020-07-26  1:37 ` Gaurav Singh
  0 siblings, 2 replies; 3+ messages in thread
From: Gaurav Singh @ 2020-07-25 18:14 UTC (permalink / raw)
  To: gaurav1086, Shuah Khan, Tejun Heo, Michal Koutný,
	Roman Gushchin, Chris Down, Andrew Morton, Christian Brauner,
	open list:KERNEL SELFTEST FRAMEWORK, open list

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

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
 tools/testing/selftests/cgroup/cgroup_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c
index 8a637ca7d73a..05853b0b8831 100644
--- a/tools/testing/selftests/cgroup/cgroup_util.c
+++ b/tools/testing/selftests/cgroup/cgroup_util.c
@@ -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;
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [cgroup/testing] cg_read_strcmp: Fix null pointer dereference
  2020-07-25 18:14 [PATCH] [cgroup/testing] cg_read_strcmp: Fix null pointer dereference Gaurav Singh
@ 2020-07-25 20:23 ` Chris Down
  2020-07-26  1:37 ` Gaurav Singh
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Down @ 2020-07-25 20:23 UTC (permalink / raw)
  To: Gaurav Singh
  Cc: Shuah Khan, Tejun Heo, Michal Koutný,
	Roman Gushchin, Andrew Morton, Christian Brauner,
	open list:KERNEL SELFTEST FRAMEWORK, open list

Gaurav Singh writes:
>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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] [cgroup/testing] cg_read_strcmp: Fix null pointer dereference
  2020-07-25 18:14 [PATCH] [cgroup/testing] cg_read_strcmp: Fix null pointer dereference Gaurav Singh
  2020-07-25 20:23 ` Chris Down
@ 2020-07-26  1:37 ` Gaurav Singh
  1 sibling, 0 replies; 3+ messages in thread
From: Gaurav Singh @ 2020-07-26  1:37 UTC (permalink / raw)
  To: gaurav1086, Shuah Khan, Tejun Heo, Michal Koutný,
	Andrew Morton, Roman Gushchin, Christian Brauner, Chris Down,
	open list:KERNEL SELFTEST FRAMEWORK, open list

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

Signed-off-by: Gaurav Singh <gaurav1086@gmail.com>
---
 tools/testing/selftests/cgroup/cgroup_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c
index 8a637ca7d73a..05853b0b8831 100644
--- a/tools/testing/selftests/cgroup/cgroup_util.c
+++ b/tools/testing/selftests/cgroup/cgroup_util.c
@@ -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;
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-25 18:14 [PATCH] [cgroup/testing] cg_read_strcmp: Fix null pointer dereference Gaurav Singh
2020-07-25 20:23 ` Chris Down
2020-07-26  1:37 ` Gaurav Singh

Linux-kselftest Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-kselftest/0 linux-kselftest/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-kselftest linux-kselftest/ https://lore.kernel.org/linux-kselftest \
		linux-kselftest@vger.kernel.org
	public-inbox-index linux-kselftest

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kselftest


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git