bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/bpf: fix a test for snprintf() overflow
@ 2022-07-19  9:50 Dan Carpenter
  2022-07-19 17:22 ` Martin KaFai Lau
  2022-07-19 17:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2022-07-19  9:50 UTC (permalink / raw)
  To: Andrii Nakryiko, Martin KaFai Lau
  Cc: Daniel Borkmann, Andrii Nakryiko, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Mykola Lysenko, Shuah Khan, Hengqi Chen, Quentin Monnet,
	Kumar Kartikeya Dwivedi, bpf, linux-kselftest, kernel-janitors

The snprintf() function returns the number of bytes which *would*
have been copied if there were space.  In other words, it can be
> sizeof(pin_path).

Fixes: c0fa1b6c3efc ("bpf: btf: Add BTF tests")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 tools/testing/selftests/bpf/prog_tests/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/btf.c b/tools/testing/selftests/bpf/prog_tests/btf.c
index 941b0100bafa..ef6528b8084c 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf.c
@@ -5338,7 +5338,7 @@ static void do_test_pprint(int test_num)
 	ret = snprintf(pin_path, sizeof(pin_path), "%s/%s",
 		       "/sys/fs/bpf", test->map_name);
 
-	if (CHECK(ret == sizeof(pin_path), "pin_path %s/%s is too long",
+	if (CHECK(ret >= sizeof(pin_path), "pin_path %s/%s is too long",
 		  "/sys/fs/bpf", test->map_name)) {
 		err = -1;
 		goto done;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/bpf: fix a test for snprintf() overflow
  2022-07-19  9:50 [PATCH] selftests/bpf: fix a test for snprintf() overflow Dan Carpenter
@ 2022-07-19 17:22 ` Martin KaFai Lau
  2022-07-19 17:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Martin KaFai Lau @ 2022-07-19 17:22 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Andrii Nakryiko, Daniel Borkmann, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Mykola Lysenko, Shuah Khan, Hengqi Chen, Quentin Monnet,
	Kumar Kartikeya Dwivedi, bpf, linux-kselftest, kernel-janitors

On Tue, Jul 19, 2022 at 12:50:32PM +0300, Dan Carpenter wrote:
> The snprintf() function returns the number of bytes which *would*
> have been copied if there were space.  In other words, it can be
> > sizeof(pin_path).
The current test does not fail on this check,
so this could be bpf-next.

Acked-by: Martin KaFai Lau <kafai@fb.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] selftests/bpf: fix a test for snprintf() overflow
  2022-07-19  9:50 [PATCH] selftests/bpf: fix a test for snprintf() overflow Dan Carpenter
  2022-07-19 17:22 ` Martin KaFai Lau
@ 2022-07-19 17:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-19 17:50 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: andrii, kafai, daniel, song, yhs, john.fastabend, kpsingh, sdf,
	haoluo, jolsa, mykolal, shuah, hengqi.chen, quentin, memxor, bpf,
	linux-kselftest, kernel-janitors

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Tue, 19 Jul 2022 12:50:32 +0300 you wrote:
> The snprintf() function returns the number of bytes which *would*
> have been copied if there were space.  In other words, it can be
> > sizeof(pin_path).
> 
> Fixes: c0fa1b6c3efc ("bpf: btf: Add BTF tests")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> [...]

Here is the summary with links:
  - selftests/bpf: fix a test for snprintf() overflow
    https://git.kernel.org/bpf/bpf-next/c/c5d22f4cfe8d

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-19 17:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19  9:50 [PATCH] selftests/bpf: fix a test for snprintf() overflow Dan Carpenter
2022-07-19 17:22 ` Martin KaFai Lau
2022-07-19 17:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).