All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf: remove pointless code from bpf_do_trace_printk()
@ 2021-04-21 19:07 Rasmus Villemoes
  2021-04-22  3:32 ` Andrii Nakryiko
  0 siblings, 1 reply; 10+ messages in thread
From: Rasmus Villemoes @ 2021-04-21 19:07 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Alan Maguire, Steven Rostedt, bpf, linux-kernel, Rasmus Villemoes

The comment is wrong. snprintf(buf, 16, "") and snprintf(buf, 16,
"%s", "") etc. will certainly put '\0' in buf[0]. The only case where
snprintf() does not guarantee a nul-terminated string is when it is
given a buffer size of 0 (which of course prevents it from writing
anything at all to the buffer).

Remove it before it gets cargo-culted elsewhere.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 kernel/trace/bpf_trace.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index b0c45d923f0f..4ee55df84cd3 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -412,9 +412,6 @@ static __printf(1, 0) int bpf_do_trace_printk(const char *fmt, ...)
 	va_start(ap, fmt);
 	ret = vsnprintf(buf, sizeof(buf), fmt, ap);
 	va_end(ap);
-	/* vsnprintf() will not append null for zero-length strings */
-	if (ret == 0)
-		buf[0] = '\0';
 	trace_bpf_trace_printk(buf);
 	raw_spin_unlock_irqrestore(&trace_printk_lock, flags);
 
-- 
2.29.2


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

end of thread, other threads:[~2021-04-22 18:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 19:07 [PATCH] bpf: remove pointless code from bpf_do_trace_printk() Rasmus Villemoes
2021-04-22  3:32 ` Andrii Nakryiko
2021-04-22  7:13   ` Rasmus Villemoes
2021-04-22  9:23     ` Florent Revest
2021-04-22 10:09       ` Rasmus Villemoes
2021-04-22 12:36         ` Florent Revest
2021-04-22 15:34           ` Florent Revest
2021-04-22 15:43             ` Alexei Starovoitov
2021-04-22 15:46               ` Florent Revest
2021-04-22 18:38       ` Andrii Nakryiko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.