Re: [PATCH bpf-next v2] libbpf: fix build error introduced by legacy kprobe feature
From: Rafael David Tinoco <hidden>
Date: 2021-09-14 21:39:14
- char cmd[192], probename[128], probefunc[128]; + char cmd[288] = "\0", probename[128] = "\0", probefunc[128] = "\0"; const char *file = "/sys/kernel/debug/tracing/kprobe_events";
I had gcc-10 with:
libbpf.c: In function ‘poke_kprobe_events’:
libbpf.c:9012:37: error: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size between 62 and 189 [-Werror=format-truncation=]
9012 | snprintf(cmd, sizeof(cmd), "%c:%s %s",
| ^~
In file included from /usr/include/stdio.h:866,
from libbpf.c:17:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 4 and 258 bytes into a destination of size 192
71 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72 | __glibc_objsize (__s), __fmt,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73 | __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
locally AND it fixed the issue for me but Alexei reported:
https://github.com/kernel-patches/bpf/runs/3603448190
with a truncation of max 258 bytes. I raised cmd size to 288.
Let's see if that fixes the issue.