BPF List
 help / color / mirror / Atom feed
* [PATCH] libbpf: avoid possible use of uninitialized mod_len
@ 2025-07-29  9:45 Achill Gilgenast
  2025-07-29 16:17 ` Yonghong Song
  0 siblings, 1 reply; 6+ messages in thread
From: Achill Gilgenast @ 2025-07-29  9:45 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Viktor Malik, bpf
  Cc: linux-kernel, Achill Gilgenast, Martin KaFai Lau,
	Eduard Zingerman, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa

If not fn_name, mod_len does never get initialized which fails now with
gcc15 on Alpine Linux edge:

	libbpf.c: In function 'find_kernel_btf_id.constprop':
	libbpf.c:10100:33: error: 'mod_len' may be used uninitialized [-Werror=maybe-uninitialized]
	10100 |                 if (mod_name && strncmp(mod->name, mod_name, mod_len) != 0)
	      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	libbpf.c:10070:21: note: 'mod_len' was declared here
	10070 |         int ret, i, mod_len;
	      |                     ^~~~~~~

Fixes: 8f8a024272f3 ("libbpf: support "module: Function" syntax for tracing programs")
Signed-off-by: Achill Gilgenast <fossdd@pwned.life>
---
 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 e067cb5776bd..fb4d92c5c339 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -10086,27 +10086,27 @@ static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd, int t
 	btf__free(btf);
 	if (err <= 0) {
 		pr_warn("%s is not found in prog's BTF\n", name);
 		goto out;
 	}
 out:
 	return err;
 }
 
 static int find_kernel_btf_id(struct bpf_object *obj, const char *attach_name,
 			      enum bpf_attach_type attach_type,
 			      int *btf_obj_fd, int *btf_type_id)
 {
-	int ret, i, mod_len;
+	int ret, i, mod_len = 0;
 	const char *fn_name, *mod_name = NULL;
 
 	fn_name = strchr(attach_name, ':');
 	if (fn_name) {
 		mod_name = attach_name;
 		mod_len = fn_name - mod_name;
 		fn_name++;
 	}
 
 	if (!mod_name || strncmp(mod_name, "vmlinux", mod_len) == 0) {
 		ret = find_attach_btf_id(obj->btf_vmlinux,
 					 mod_name ? fn_name : attach_name,
 					 attach_type);
-- 
2.50.1


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

end of thread, other threads:[~2025-08-01 15:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-29  9:45 [PATCH] libbpf: avoid possible use of uninitialized mod_len Achill Gilgenast
2025-07-29 16:17 ` Yonghong Song
2025-07-30 16:13   ` Eduard Zingerman
2025-08-01 11:46     ` Achill Gilgenast
2025-08-01 12:04       ` Achill Gilgenast
2025-08-01 15:16         ` Alexei Starovoitov

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