summaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2022-07-19 12:51:28 +0300
committerAlexei Starovoitov <ast@kernel.org>2022-07-19 10:47:31 -0700
commitb77ffb30cfc5f58e957571d8541c6a7e3da19221 (patch)
tree08d945ad390d43a3da4ab590fe3264f215b867cf /tools/lib/bpf
parentc5d22f4cfe8dfb93f1db0a1e7e2e7ebc41395d98 (diff)
downloadlinux-b77ffb30cfc5f58e957571d8541c6a7e3da19221.tar.bz2
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 <dan.carpenter@oracle.com> Acked-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/r/YtZ+oAySqIhFl6/J@kili Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r--tools/lib/bpf/gen_loader.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/lib/bpf/gen_loader.c b/tools/lib/bpf/gen_loader.c
index 927745b08014..23f5c46708f8 100644
--- a/tools/lib/bpf/gen_loader.c
+++ b/tools/lib/bpf/gen_loader.c
@@ -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;
}