2023-12-18 15:19:40

by Richard Fitzgerald

[permalink] [raw]
Subject: [PATCH] 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().

Signed-off-by: Richard Fitzgerald <[email protected]>
Fixes: 6d696c4695c5 ("kunit: add ability to run tests after boot using debugfs")
---
lib/kunit/test.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/kunit/test.c b/lib/kunit/test.c
index e803d998e855..ea7f0913e55a 100644
--- a/lib/kunit/test.c
+++ b/lib/kunit/test.c
@@ -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



2023-12-19 21:03:57

by Rae Moar

[permalink] [raw]
Subject: Re: [PATCH] kunit: Fix NULL-dereference in kunit_init_suite() if suite->log is NULL

On Mon, Dec 18, 2023 at 10:17 AM Richard Fitzgerald
<[email protected]> wrote:
>
> 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().
>
> Signed-off-by: Richard Fitzgerald <[email protected]>
> Fixes: 6d696c4695c5 ("kunit: add ability to run tests after boot using debugfs")

Hello!

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

Reviewed-by: Rae Moar <[email protected]>

-Rae

> ---
> lib/kunit/test.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lib/kunit/test.c b/lib/kunit/test.c
> index e803d998e855..ea7f0913e55a 100644
> --- a/lib/kunit/test.c
> +++ b/lib/kunit/test.c
> @@ -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
>

2023-12-22 08:38:34

by David Gow

[permalink] [raw]
Subject: Re: [PATCH] kunit: Fix NULL-dereference in kunit_init_suite() if suite->log is NULL

On Mon, 18 Dec 2023 at 23:17, Richard Fitzgerald
<[email protected]> wrote:
>
> 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().
>
> Signed-off-by: Richard Fitzgerald <[email protected]>
> Fixes: 6d696c4695c5 ("kunit: add ability to run tests after boot using debugfs")
> ---

Acked-by: David Gow <[email protected]>

Cheers,
-- David


> lib/kunit/test.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lib/kunit/test.c b/lib/kunit/test.c
> index e803d998e855..ea7f0913e55a 100644
> --- a/lib/kunit/test.c
> +++ b/lib/kunit/test.c
> @@ -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
>


Attachments:
smime.p7s (3.91 kB)
S/MIME Cryptographic Signature

2023-12-30 07:20:17

by Muhammad Usama Anjum

[permalink] [raw]
Subject: Re: [PATCH] kunit: Fix NULL-dereference in kunit_init_suite() if suite->log is NULL

On 12/18/23 8:17 PM, Richard Fitzgerald wrote:
> 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().
>
> Signed-off-by: Richard Fitzgerald <[email protected]>
> Fixes: 6d696c4695c5 ("kunit: add ability to run tests after boot using debugfs")
Reviewed-by: Muhammad Usama Anjum <[email protected]>

> ---
> lib/kunit/test.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lib/kunit/test.c b/lib/kunit/test.c
> index e803d998e855..ea7f0913e55a 100644
> --- a/lib/kunit/test.c
> +++ b/lib/kunit/test.c
> @@ -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)

--
BR,
Muhammad Usama Anjum