diff options
author | Quentin Monnet <quentin.monnet@netronome.com> | 2018-11-08 11:52:25 +0000 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-11-09 08:20:52 +0100 |
commit | 53909030aa29bffe1f8490df62176c2375135652 (patch) | |
tree | 8f36333c5fb18e5feb333c4de48be0e5b7c53bb2 /tools | |
parent | 49a249c387268882e8393dd1fafc51e3b21cb7a2 (diff) |
tools: bpftool: prevent infinite loop in get_fdinfo()
Function getline() returns -1 on failure to read a line, thus creating
an infinite loop in get_fdinfo() if the key is not found. Fix it by
calling the function only as long as we get a strictly positive return
value.
Found by copying the code for a key which is not always present...
Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool")
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bpf/bpftool/common.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index 25af85304ebe..e070b00ac309 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c @@ -304,7 +304,7 @@ char *get_fdinfo(int fd, const char *key) return NULL; } - while ((n = getline(&line, &line_n, fdi))) { + while ((n = getline(&line, &line_n, fdi)) > 0) { char *value; int len; |