tools: bpftool: fix crash on bad parameters with JSON
authorQuentin Monnet <quentin.monnet@netronome.com>
Wed, 29 Nov 2017 01:44:28 +0000 (17:44 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 30 Nov 2017 01:09:29 +0000 (02:09 +0100)
commit9b85c2d4508563f4bb1de0d971ed02fea0d0d757
treee9d2683c58114c5b9c78a058d881c117bf1fd75d
parenta39e17b2d842938e19997d2fdc0443fdd4cd8d10
tools: bpftool: fix crash on bad parameters with JSON

If bad or unrecognised parameters are specified after JSON output is
requested, `usage()` will try to output null JSON object before the
writer is created.

To prevent this, create the writer as soon as the `--json` option is
parsed.

Fixes: 004b45c0e51a ("tools: bpftool: provide JSON output for all possible commands")
Reported-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/bpf/bpftool/main.c