mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-11-16 11:44:52 +00:00
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: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
2367bd99f6
commit
1e960043e8
1 changed files with 3 additions and 0 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue