Re: [PATCH 1/5] lib/tests: string_helpers: check null terminator too
From: Jonas Rebmann
Date: Thu Sep 17 2026 - 05:07:39 EST
Hi,
On 2026-09-17 09:14, Andy Shevchenko wrote:
On Wed, Sep 16, 2026 at 07:38:06PM +0200, Jonas Rebmann wrote:
string_unescape() returns the number of character written to dst, not
counting the null terminator which is always written.
Ensure string_unescape has included the null terminator by adding a
separate check.
...
- KUNIT_ASSERT_EQ_MSG(test, q_real, q_test, "name:%s", name);
+ KUNIT_EXPECT_EQ_MSG(test, q_real, q_test, "name:%s", name);
char *out_test, size_t q_test)
The commit message doesn't explain why it's safe to continue the test if the
first assertion fails. Care to elaborate?
It is safe against out of bounds access because both buffers are
allocated by the callers, not by the function under test, and the
comparison is done for the number of bytes expected, not whatever the
function under test indicates was written.
I would add this explanation to the v2 commit message
--
Pengutronix e.K. | Jonas Rebmann |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |