summaryrefslogtreecommitdiff
path: root/lib/kunit/executor_test.c
diff options
context:
space:
mode:
authorDaniel Latypov <dlatypov@google.com>2021-10-02 04:36:35 +0300
committerShuah Khan <skhan@linuxfoundation.org>2021-10-19 23:18:49 +0300
commitcd94fbc2cafb61cc1394cdba3f92b99ce07b03ae (patch)
tree552c3c1e2d16cb44a581407f4045ea3ecc0bba86 /lib/kunit/executor_test.c
parenta127b154a8f231709754b5d56a501163dd837459 (diff)
downloadlinux-cd94fbc2cafb61cc1394cdba3f92b99ce07b03ae.tar.xz
kunit: fix too small allocation when using suite-only kunit.filter_glob
When a user filters by a suite and not a test, e.g. $ ./tools/testing/kunit/kunit.py run 'suite_name' it hits this code const int len = strlen(filter_glob); ... parsed->suite_glob = kmalloc(len, GFP_KERNEL); which fails to allocate space for the terminating NULL. Somehow, it seems like we can't easily reproduce this under UML, so the existing `parse_filter_test()` didn't catch this. Fix this by allocating `len + 1` and switch to kzalloc() just to be a bit more defensive. We're only going to run this code once per kernel boot, and it should never be very long. Also update the unit tests to be a bit more cautious. This bug showed up as a NULL pointer dereference here: > KUNIT_EXPECT_STREQ(test, (const char *)filtered.start[0][0]->name, "suite0"); `filtered.start[0][0]` was NULL, and `name` is at offset 0 in the struct, so `...->name` was also NULL. Fixes: 3b29021ddd10 ("kunit: tool: allow filtering test cases via glob") Reported-by: kernel test robot <oliver.sang@intel.com> Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Acked-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Diffstat (limited to 'lib/kunit/executor_test.c')
-rw-r--r--lib/kunit/executor_test.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c
index edbd8184dcd7..4ed57fd94e42 100644
--- a/lib/kunit/executor_test.c
+++ b/lib/kunit/executor_test.c
@@ -149,6 +149,7 @@ static void filter_suites_test(struct kunit *test)
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, filtered.start);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, filtered.start[0]);
+ KUNIT_ASSERT_NOT_ERR_OR_NULL(test, filtered.start[0][0]);
KUNIT_EXPECT_STREQ(test, (const char *)filtered.start[0][0]->name, "suite0");
}