* [PATCH][next] kunit: fix dereference of suite before it has been null checked
@ 2020-04-02 15:03 Colin King
2020-04-02 15:24 ` Alan Maguire
0 siblings, 1 reply; 2+ messages in thread
From: Colin King @ 2020-04-02 15:03 UTC (permalink / raw)
To: Brendan Higgins, Frank Rowand, Shuah Khan, Alan Maguire,
linux-kselftest, kunit-dev
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Currently pointer 'suite' is dereferenced when variable success
is being initialized before the pointer is null checked. Fix this
by only dereferencing suite after is has been null checked.
Addresses-Coverity: ("Dereference before null check")
Fixes: e2219db280e3 ("kunit: add debugfs /sys/kernel/debug/kunit/<suite>/results display")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
lib/kunit/debugfs.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/kunit/debugfs.c b/lib/kunit/debugfs.c
index 9214c493d8b7..05547642f37c 100644
--- a/lib/kunit/debugfs.c
+++ b/lib/kunit/debugfs.c
@@ -52,12 +52,13 @@ static void debugfs_print_result(struct seq_file *seq,
static int debugfs_print_results(struct seq_file *seq, void *v)
{
struct kunit_suite *suite = (struct kunit_suite *)seq->private;
- bool success = kunit_suite_has_succeeded(suite);
+ bool success;
struct kunit_case *test_case;
if (!suite || !suite->log)
return 0;
+ success = kunit_suite_has_succeeded(suite);
seq_printf(seq, "%s", suite->log);
kunit_suite_for_each_test_case(suite, test_case)
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH][next] kunit: fix dereference of suite before it has been null checked
2020-04-02 15:03 [PATCH][next] kunit: fix dereference of suite before it has been null checked Colin King
@ 2020-04-02 15:24 ` Alan Maguire
0 siblings, 0 replies; 2+ messages in thread
From: Alan Maguire @ 2020-04-02 15:24 UTC (permalink / raw)
To: Colin King
Cc: Brendan Higgins, Frank Rowand, Shuah Khan, Alan Maguire,
linux-kselftest, kunit-dev, kernel-janitors, linux-kernel
On Thu, 2 Apr 2020, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently pointer 'suite' is dereferenced when variable success
> is being initialized before the pointer is null checked. Fix this
> by only dereferencing suite after is has been null checked.
>
> Addresses-Coverity: ("Dereference before null check")
> Fixes: e2219db280e3 ("kunit: add debugfs /sys/kernel/debug/kunit/<suite>/results display")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
Thanks for spotting this!
Alan
> ---
> lib/kunit/debugfs.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/kunit/debugfs.c b/lib/kunit/debugfs.c
> index 9214c493d8b7..05547642f37c 100644
> --- a/lib/kunit/debugfs.c
> +++ b/lib/kunit/debugfs.c
> @@ -52,12 +52,13 @@ static void debugfs_print_result(struct seq_file *seq,
> static int debugfs_print_results(struct seq_file *seq, void *v)
> {
> struct kunit_suite *suite = (struct kunit_suite *)seq->private;
> - bool success = kunit_suite_has_succeeded(suite);
> + bool success;
> struct kunit_case *test_case;
>
> if (!suite || !suite->log)
> return 0;
>
> + success = kunit_suite_has_succeeded(suite);
> seq_printf(seq, "%s", suite->log);
>
> kunit_suite_for_each_test_case(suite, test_case)
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-04-02 15:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-02 15:03 [PATCH][next] kunit: fix dereference of suite before it has been null checked Colin King
2020-04-02 15:24 ` Alan Maguire
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).