Re: [PATCH 1/2] lib/test_printf.c: Add ip6 tests

From: Rasmus Villemoes
Date: Tue Aug 30 2022 - 03:32:33 EST


On 30/08/2022 03.47, Sergey Senozhatsky wrote:
> On (22/08/29 20:31), Kent Overstreet wrote:
>> diff --git a/lib/test_printf.c b/lib/test_printf.c
>> index 4bd15a593f..6a56dbf076 100644
>> --- a/lib/test_printf.c
>> +++ b/lib/test_printf.c
>> @@ -18,6 +18,7 @@
>> #include <linux/dcache.h>
>> #include <linux/socket.h>
>> #include <linux/in.h>
>> +#include <linux/in6.h>
>>
>> #include <linux/gfp.h>
>> #include <linux/mm.h>
>> @@ -61,6 +62,9 @@ do_test(int bufsize, const char *expect, int elen,
>> pr_warn("vsnprintf(buf, %d, \"%s\", ...) returned %d, expected %d\n",
>> bufsize, fmt, ret, elen);
>> return 1;
>> + pr_warn("vsnprintf(buf, %d, \"%s\", ...) returned %d, expected %d (%s != %s)\n",
>> + bufsize, fmt, ret, elen, test_buffer, expect);
>> + return 1;
>> }
>
> I assume you intended to replace first pr_warn() with the second one?

Probably, but that's not ok. The test framework does not trust
vsnprintf(), especially not when it does not behave as expected. So I
very much carefully do not treat the buffer as a nul-terminated string
until I have verified that it does have a nul character (that's tested a
few lines below), and then when I compare the buffer contents can I pass
it as a %s argument. Also note how that test takes the 'we may be
testing a truncated write' into consideration, by printing the expect
string via %.*s.

tl;dr, please just remove that hunk.

Rasmus