Skip to contentSkip to conversation

kunit: Fix NULL-dereference in kunit_init_suite() if suite->log is NULL

PATCH In review Richard Fitzgerald 4 participants 4 messages Dec 18, 2023 – Dec 30, 2023

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

PATCH 1/1 kunit: Fix NULL-dereference in kunit_init_suite() if suite->log is NULL

suite->log must be checked for NULL before passing it to string_stream_clear(). This was done in kunit_init_test() but was missing from kunit_init_suite().

Fixes 6d696c4695c5 ("kunit: add ability to run tests after boot using debugfs")
---
 lib/kunit/test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/kunit/test.c +3 -1
index e803d998e855..ea7f0913e55a 100644
@@ -658,7 +658,9 @@ static void kunit_init_suite(struct kunit_suite *suite)
 	kunit_debugfs_create_suite(suite);
 	suite->status_comment[0] = '\0';
 	suite->suite_init_err = 0;
-	string_stream_clear(suite->log);
+
+	if (suite->log)
+		string_stream_clear(suite->log);
 }
 
 bool kunit_enabled(void)
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Richard Fitzgerald

suite->log must be checked for NULL before passing it to string_stream_clear(). This was done in kunit_init_test() but was missing from kunit_init_suite().

Fixes 6d696c4695c5 ("kunit: add ability to run tests after boot using debugfs")

Hello!

This looks good! Thanks! Sorry I did not catch this earlier.

-Rae

Quoted 22 lines
---
 lib/kunit/test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/kunit/test.c +3 -2
index e803d998e855..ea7f0913e55a 100644
@@ -658,7 +658,9 @@ static void kunit_init_suite(struct kunit_suite *suite)
        kunit_debugfs_create_suite(suite);
        suite->status_comment[0] = '\0';
        suite->suite_init_err = 0;
-       string_stream_clear(suite->log);
+
+       if (suite->log)
+               string_stream_clear(suite->log);
 }
 
 bool kunit_enabled(void)
--

2.30.2

Acked-by on v1 1/1
#2 lore raw
In reply to Richard Fitzgerald
Quoted 8 lines · Richard Fitzgerald

suite->log must be checked for NULL before passing it to string_stream_clear(). This was done in kunit_init_test() but was missing from kunit_init_suite().

Fixes 6d696c4695c5 ("kunit: add ability to run tests after boot using debugfs")

---

Cheers,
-- David

Quoted 21 lines
 lib/kunit/test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/kunit/test.c +3 -2
index e803d998e855..ea7f0913e55a 100644
@@ -658,7 +658,9 @@ static void kunit_init_suite(struct kunit_suite *suite)
        kunit_debugfs_create_suite(suite);
        suite->status_comment[0] = '\0';
        suite->suite_init_err = 0;
-       string_stream_clear(suite->log);
+
+       if (suite->log)
+               string_stream_clear(suite->log);
 }
 
 bool kunit_enabled(void)
--

2.30.2

Reviewed-by on v1 1/1
#3 lore raw
In reply to Richard Fitzgerald
Quoted 6 lines · Richard Fitzgerald

suite->log must be checked for NULL before passing it to string_stream_clear(). This was done in kunit_init_test() but was missing from kunit_init_suite().

Fixes 6d696c4695c5 ("kunit: add ability to run tests after boot using debugfs")
Quoted 19 lines
---
 lib/kunit/test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/kunit/test.c +3 -1
index e803d998e855..ea7f0913e55a 100644
@@ -658,7 +658,9 @@ static void kunit_init_suite(struct kunit_suite *suite)
 	kunit_debugfs_create_suite(suite);
 	suite->status_comment[0] = '\0';
 	suite->suite_init_err = 0;
-	string_stream_clear(suite->log);
+
+	if (suite->log)
+		string_stream_clear(suite->log);
 }
 
 bool kunit_enabled(void)
Signature · 2 lines
BR,
Muhammad Usama Anjum