All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2][next] kunit/overflow: Add tests for STACK_FLEX_ARRAY_SIZE() helper
Date: Tue, 22 Apr 2025 13:39:49 -0700	[thread overview]
Message-ID: <202504221339.65ED2943C@keescook> (raw)
In-Reply-To: <8cf48c3f9d8ef9b999d87cc0a822ffe539bf7a64.1745342381.git.gustavoars@kernel.org>

On Tue, Apr 22, 2025 at 11:22:08AM -0600, Gustavo A. R. Silva wrote:
> Add a couple of tests for new STACK_FLEX_ARRAY_SIZE() helper.
> 
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
>  lib/tests/overflow_kunit.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/tests/overflow_kunit.c b/lib/tests/overflow_kunit.c
> index 894691b4411a..3beb497a44be 100644
> --- a/lib/tests/overflow_kunit.c
> +++ b/lib/tests/overflow_kunit.c
> @@ -1210,6 +1210,9 @@ static void DEFINE_FLEX_test(struct kunit *test)
>  	KUNIT_EXPECT_EQ(test, __struct_size(empty->array), 0);
>  	KUNIT_EXPECT_EQ(test, __member_size(empty->array), 0);
>  
> +	KUNIT_EXPECT_EQ(test, STACK_FLEX_ARRAY_SIZE(two, array), 2);
> +	KUNIT_EXPECT_EQ(test, STACK_FLEX_ARRAY_SIZE(eight, array), 8);

Nice! Can you add a 0 test for "empty" as well?

> +
>  	/* If __counted_by is not being used, array size will have the on-stack size. */
>  	if (!IS_ENABLED(CONFIG_CC_HAS_COUNTED_BY))
>  		array_size_override = 2 * sizeof(s16);
> -- 
> 2.43.0
> 

-- 
Kees Cook

  reply	other threads:[~2025-04-22 20:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22 17:20 [PATCH 0/2][next] Add STACK_FLEX_ARRAY_SIZE() helper Gustavo A. R. Silva
2025-04-22 17:21 ` [PATCH 1/2][next] overflow: " Gustavo A. R. Silva
2025-04-22 20:39   ` Kees Cook
2025-04-22 17:22 ` [PATCH 2/2][next] kunit/overflow: Add tests for " Gustavo A. R. Silva
2025-04-22 20:39   ` Kees Cook [this message]
2025-04-22 20:48     ` Gustavo A. R. Silva

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=202504221339.65ED2943C@keescook \
    --to=kees@kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.