Message ID | 20200725181506.20199-1-gaurav1086@gmail.com (mailing list archive) |
---|---|
State | Mainlined |
Commit | d830020656c5b68ced962ed3cb51a90e0a89d4c4 |
Headers | show |
Series | [cgroup/testing] cg_read_strcmp: Fix null pointer dereference | expand |
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?
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;
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(-)