Commit 1e960043 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by Daniel Borkmann

tools: libbpf: handle NULL program gracefully in bpf_program__nth_fd()

bpf_map__fd() handles NULL map gracefully and returns -EINVAL.
bpf_program__fd() and bpf_program__nth_fd() crash in this case.
Make the behaviour more consistent by validating prog pointer
as well.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 2367bd99
...@@ -1991,6 +1991,9 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n) ...@@ -1991,6 +1991,9 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n)
{ {
int fd; int fd;
if (!prog)
return -EINVAL;
if (n >= prog->instances.nr || n < 0) { if (n >= prog->instances.nr || n < 0) {
pr_warning("Can't get the %dth fd from program %s: only %d instances\n", pr_warning("Can't get the %dth fd from program %s: only %d instances\n",
n, prog->section_name, prog->instances.nr); n, prog->section_name, prog->instances.nr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment