libbpf: fix an snprintf() overflow check
Subsystems (3)
PATCH 1/1 libbpf: fix an snprintf() overflow check
The snprintf() function returns the number of bytes it *would* have copied if there were enough space. So it can return > the sizeof(gen->attach_target).
Fixes 67234743736a ("libbpf: Generate loader program out of BPF ELF file.")
Signed-off-by Dan Carpenter <[email protected]>
--- tools/lib/bpf/gen_loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/gen_loader.c +1 -1
@@ -533,7 +533,7 @@ void bpf_gen__record_attach_target(struct bpf_gen *gen, const char *attach_name, gen->attach_kind = kind; ret =snprintf (gen->attach_target,sizeof (gen->attach_target),"%s%s" , prefix, attach_name); -if (ret ==sizeof (gen->attach_target)) +if (ret >=sizeof (gen->attach_target)) gen->error = -ENOSPC ; }
Signature · 1 line
2.35.1
Quoted 3 lines · Dan Carpenter
The
snprintf()function returns the number of bytes it *would* have copied if there were enough space. So it can return > thesizeof(gen->attach_target).
Acked-by Martin KaFai Lau <[email protected]>
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 8 lines · On Tue, 19 Jul 2022 12:51:28 +0300 you wrote:
The
snprintf()function returns the number of bytes it *would* have copied if there were enough space. So it can return > thesizeof(gen->attach_target).Fixes 67234743736a ("libbpf: Generate loader program out of BPF ELF file.")Signed-off-by Dan Carpenter <[email protected]>[...]
Here is the summary with links:
- libbpf: fix an snprintf() overflow check
https://git.kernel.org/bpf/bpf-next/c/b77ffb30cfc5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html