]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
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)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 9 Nov 2018 07:20:52 +0000 (08:20 +0100)
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>
tools/bpf/bpftool/common.c

index 25af85304ebee3b073d9e7d0036038c5c4c05d68..e070b00ac30944170136709b539f7c30def46f4b 100644 (file)
@@ -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;