tools: bpftool: prevent infinite loop in get_fdinfo()
authorQuentin Monnet <quentin.monnet@netronome.com>
Thu, 8 Nov 2018 11:52:25 +0000 (11:52 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 17 Dec 2018 08:24:30 +0000 (09:24 +0100)
commitb42ab52844123694b7f0524be08c96c8408aaa37
treed05812aabb72a8d05c3de27bb0370a5df991abcf
parent136c523734297fe1905978eb38e2d274b24c1f48
tools: bpftool: prevent infinite loop in get_fdinfo()

[ Upstream commit 53909030aa29bffe1f8490df62176c2375135652 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/bpf/bpftool/common.c