From mboxrd@z Thu Jan 1 00:00:00 1970 From: Quentin Monnet Subject: [PATCH bpf 1/4] tools: bpftool: prevent infinite loop in get_fdinfo() Date: Thu, 8 Nov 2018 11:52:25 +0000 Message-ID: <1541677948-12473-2-git-send-email-quentin.monnet@netronome.com> References: <1541677948-12473-1-git-send-email-quentin.monnet@netronome.com> Cc: netdev@vger.kernel.org, oss-drivers@netronome.com, Quentin Monnet To: Alexei Starovoitov , Daniel Borkmann Return-path: Received: from mail-wr1-f50.google.com ([209.85.221.50]:34586 "EHLO mail-wr1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726659AbeKHV1v (ORCPT ); Thu, 8 Nov 2018 16:27:51 -0500 Received: by mail-wr1-f50.google.com with SMTP id j26-v6so20959838wre.1 for ; Thu, 08 Nov 2018 03:52:43 -0800 (PST) In-Reply-To: <1541677948-12473-1-git-send-email-quentin.monnet@netronome.com> Sender: netdev-owner@vger.kernel.org List-ID: 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 Reviewed-by: Jakub Kicinski --- tools/bpf/bpftool/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index 1149565be4b1..acd839e0e801 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c @@ -312,7 +312,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; -- 2.7.4