From: Muhammad Usama Anjum <usama.anjum@collabora.com>
To: Richard Fitzgerald <rf@opensource.cirrus.com>,
brendan.higgins@linux.dev, davidgow@google.com, rmoar@google.com
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>,
linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
linux-kernel@vger.kernel.org, patches@opensource.cirrus.com
Subject: Re: [PATCH] kunit: Protect string comparisons against NULL
Date: Sat, 30 Dec 2023 12:17:49 +0500 [thread overview]
Message-ID: <f80fafaf-41b2-4b69-a574-424c9de18fd9@collabora.com> (raw)
In-Reply-To: <20231220155256.407974-1-rf@opensource.cirrus.com>
On 12/20/23 8:52 PM, Richard Fitzgerald wrote:
> Add NULL checks to KUNIT_BINARY_STR_ASSERTION() so that it will fail
> cleanly if either pointer is NULL, instead of causing a NULL pointer
> dereference in the strcmp().
>
> A test failure could be that a string is unexpectedly NULL. This could
> be trapped by KUNIT_ASSERT_NOT_NULL() but that would terminate the test
> at that point. It's preferable that the KUNIT_EXPECT_STR*() macros can
> handle NULL pointers as a failure.
>
> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> include/kunit/test.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/kunit/test.h b/include/kunit/test.h
> index b163b9984b33..c2ce379c329b 100644
> --- a/include/kunit/test.h
> +++ b/include/kunit/test.h
> @@ -758,7 +758,7 @@ do { \
> .right_text = #right, \
> }; \
> \
> - if (likely(strcmp(__left, __right) op 0)) \
> + if (likely((__left) && (__right) && (strcmp(__left, __right) op 0))) \
> break; \
> \
> \
--
BR,
Muhammad Usama Anjum
prev parent reply other threads:[~2023-12-30 7:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-20 15:52 [PATCH] kunit: Protect string comparisons against NULL Richard Fitzgerald
2023-12-22 8:39 ` David Gow
2024-01-04 11:52 ` Richard Fitzgerald
2023-12-30 7:17 ` Muhammad Usama Anjum [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f80fafaf-41b2-4b69-a574-424c9de18fd9@collabora.com \
--to=usama.anjum@collabora.com \
--cc=brendan.higgins@linux.dev \
--cc=davidgow@google.com \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=rf@opensource.cirrus.com \
--cc=rmoar@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox