Commit 759b94a0 authored by Taeung Song's avatar Taeung Song Committed by Daniel Borkmann

tools/bpftool: Fix segfault case regarding 'pin' arguments

Arguments of 'pin' subcommand should be checked
at the very beginning of do_pin_any().
Otherwise segfault errors can occur when using
'map pin' or 'prog pin' commands, so fix it.

  # bpftool prog pin id
  Segmentation fault

Fixes: 71bb428f ("tools: bpf: add bpftool")
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reported-by: default avatarTaehee Yoo <ap420073@gmail.com>
Signed-off-by: default avatarTaeung Song <treeze.taeung@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent bb392867
......@@ -217,6 +217,14 @@ int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32))
int err;
int fd;
if (argc < 3) {
p_err("too few arguments, id ID and FILE path is required");
return -1;
} else if (argc > 3) {
p_err("too many arguments");
return -1;
}
if (!is_prefix(*argv, "id")) {
p_err("expected 'id' got %s", *argv);
return -1;
......@@ -230,9 +238,6 @@ int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32))
}
NEXT_ARG();
if (argc != 1)
usage();
fd = get_fd_by_id(id);
if (fd < 0) {
p_err("can't get prog by id (%u): %s", id, strerror(errno));
......
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