public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf: btf: Fix vsnprintf return value check
@ 2022-07-11 21:13 Fedor Tokarev
  2022-07-11 21:42 ` Jiri Olsa
  0 siblings, 1 reply; 6+ messages in thread
From: Fedor Tokarev @ 2022-07-11 21:13 UTC (permalink / raw)
  To: Martin KaFai Lau; +Cc: bpf, linux-kernel, ftokarev

vsnprintf returns the number of characters which would have been written if
enough space had been available, excluding the terminating null byte. Thus,
the return value of 'len_left' means that the last character has been
dropped.

Signed-off-by: Fedor Tokarev <ftokarev@gmail.com>
---
 kernel/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index eb12d4f705cc..a9c1c98017d4 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -6519,7 +6519,7 @@ static void btf_snprintf_show(struct btf_show *show, const char *fmt,
 	if (len < 0) {
 		ssnprintf->len_left = 0;
 		ssnprintf->len = len;
-	} else if (len > ssnprintf->len_left) {
+	} else if (len >= ssnprintf->len_left) {
 		/* no space, drive on to get length we would have written */
 		ssnprintf->len_left = 0;
 		ssnprintf->len += len;
-- 
2.25.1


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

end of thread, other threads:[~2022-07-25  7:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-11 21:13 [PATCH] bpf: btf: Fix vsnprintf return value check Fedor Tokarev
2022-07-11 21:42 ` Jiri Olsa
2022-07-13 18:40   ` Andrii Nakryiko
2022-07-14 10:06     ` Alan Maguire
2022-07-15  7:07       ` Fedor Tokarev
2022-07-25  7:41         ` Alan Maguire

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox