[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aWYFT1yoktjDLFTm@smile.fi.intel.com>
Date: Tue, 13 Jan 2026 10:41:51 +0200
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: Feng Jiang <jiangfeng@...inos.cn>
Cc: pjw@...nel.org, palmer@...belt.com, aou@...s.berkeley.edu,
alex@...ti.fr, kees@...nel.org, andy@...nel.org,
akpm@...ux-foundation.org, ebiggers@...nel.org,
martin.petersen@...cle.com, ardb@...nel.org,
ajones@...tanamicro.com, conor.dooley@...rochip.com,
samuel.holland@...ive.com, linus.walleij@...aro.org,
nathan@...nel.org, linux-riscv@...ts.infradead.org,
linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH v2 06/14] lib/string_kunit: add correctness test for
strnlen
On Tue, Jan 13, 2026 at 04:27:40PM +0800, Feng Jiang wrote:
> Add a KUnit test for strnlen() to verify correctness across
> different string lengths and memory alignments.
...
> + for (offset = 0; offset < STRING_TEST_MAX_OFFSET; offset++) {
> + for (len = 0; len <= STRING_TEST_MAX_LEN; len++) {
> + s[offset + len] = '\0';
This should be one or two characters further so you check should also check for
non-NUL terminated strings...
> + if (len > 0)
> + KUNIT_EXPECT_EQ(test, strnlen(s + offset, len - 1), len - 1);
...or make more tests, with len - 2 at least.
> + KUNIT_EXPECT_EQ(test, strnlen(s + offset, len), len);
> + KUNIT_EXPECT_EQ(test, strnlen(s + offset, len + 1), len);
I would also add + 2 test case.
> + KUNIT_EXPECT_EQ(test, strnlen(s + offset, len + 10), len);
> + s[offset + len] = 'A';
> + }
> + }
> +}
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists