提交 53909030 编写于 作者: Q Quentin Monnet 提交者: Daniel Borkmann

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: 71bb428f ("tools: bpf: add bpftool")
Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
上级 49a249c3
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册