tools/lib/bpf/libbpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
This patch increases the size of the `probe_name` buffer in
`probe_kern_syscall_wrapper()` from `MAX_EVENT_NAME_LEN` to
`MAX_EVENT_NAME_LEN * 2`.
The change addresses a build failure in perf builds caused by GCC's
-Werror=format-truncation warning:
libbpf.c:11052:45: error: '%s' directive output may be truncated writing up to 63 bytes into a region of size between 34 and 53 [-Werror=format-truncation]
The warning is triggered by a `snprintf()` call that formats a string
using syscall names and other identifiers. In some cases, the buffer
size is insufficient, leading to potential truncation.
Debug builds pass because they do not treat warnings as errors, but
perf builds fail due to `-Werror`.
Increasing the buffer size ensures that the formatted string fits
safely, resolving the issue without affecting functionality.
Signed-off-by: Sanjay Chitroda <quic_ckantibh@quicinc.com>
---
tools/lib/bpf/libbpf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 8f5a81b672e1..9413e86476da 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -11290,7 +11290,7 @@ int probe_kern_syscall_wrapper(int token_fd)
return pfd >= 0 ? 1 : 0;
} else { /* legacy mode */
- char probe_name[MAX_EVENT_NAME_LEN];
+ char probe_name[MAX_EVENT_NAME_LEN * 2];
gen_probe_legacy_event_name(probe_name, sizeof(probe_name), syscall_name, 0);
if (add_kprobe_event_legacy(probe_name, false, syscall_name, 0) < 0)
--
2.34.1
On Wed, Sep 17, 2025 at 5:44 AM Sanjay Chitroda <quic_ckantibh@quicinc.com> wrote: > > This patch increases the size of the `probe_name` buffer in > `probe_kern_syscall_wrapper()` from `MAX_EVENT_NAME_LEN` to > `MAX_EVENT_NAME_LEN * 2`. > > The change addresses a build failure in perf builds caused by GCC's > -Werror=format-truncation warning: > > libbpf.c:11052:45: error: '%s' directive output may be truncated writing up to 63 bytes into a region of size between 34 and 53 [-Werror=format-truncation] > We write into that buffer with snprintf() which will handle truncation and leave properly zero terminated string. GCC being overly aggressive with its warning? Or am I missing something? pw-bot: cr > The warning is triggered by a `snprintf()` call that formats a string > using syscall names and other identifiers. In some cases, the buffer > size is insufficient, leading to potential truncation. > > Debug builds pass because they do not treat warnings as errors, but > perf builds fail due to `-Werror`. > > Increasing the buffer size ensures that the formatted string fits > safely, resolving the issue without affecting functionality. > > Signed-off-by: Sanjay Chitroda <quic_ckantibh@quicinc.com> > --- > tools/lib/bpf/libbpf.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 8f5a81b672e1..9413e86476da 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -11290,7 +11290,7 @@ int probe_kern_syscall_wrapper(int token_fd) > > return pfd >= 0 ? 1 : 0; > } else { /* legacy mode */ > - char probe_name[MAX_EVENT_NAME_LEN]; > + char probe_name[MAX_EVENT_NAME_LEN * 2]; > > gen_probe_legacy_event_name(probe_name, sizeof(probe_name), syscall_name, 0); > if (add_kprobe_event_legacy(probe_name, false, syscall_name, 0) < 0) > -- > 2.34.1 >
© 2016 - 2025 Red Hat, Inc.