From patchwork Thu Aug 18 17:32:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarod Wilson X-Patchwork-Id: 9289105 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A6C7C6086A for ; Fri, 19 Aug 2016 01:51:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9827729149 for ; Fri, 19 Aug 2016 01:51:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B6932915A; Fri, 19 Aug 2016 01:51:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB1E82914A for ; Fri, 19 Aug 2016 01:51:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755311AbcHSBvn (ORCPT ); Thu, 18 Aug 2016 21:51:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40968 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754813AbcHSBvm (ORCPT ); Thu, 18 Aug 2016 21:51:42 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62349C0567A0; Thu, 18 Aug 2016 17:32:39 +0000 (UTC) Received: from hp-dl360pgen8-07.khw.lab.eng.bos.redhat.com (hp-dl360pgen8-07.khw.lab.eng.bos.redhat.com [10.16.184.47]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7IHWUAI018884; Thu, 18 Aug 2016 13:32:38 -0400 From: Jarod Wilson To: linux-rdma@vger.kernel.org Cc: Jarod Wilson , Gil Rockah Subject: [PATCH perftest 16/23] perftest: check for NULL fgets() returns Date: Thu, 18 Aug 2016 13:32:11 -0400 Message-Id: <1471541538-20270-17-git-send-email-jarod@redhat.com> In-Reply-To: <1471541538-20270-1-git-send-email-jarod@redhat.com> References: <1471541538-20270-1-git-send-email-jarod@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 18 Aug 2016 17:32:39 +0000 (UTC) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Check for fgets() failure in addition to fopen() failure and take appropriate action. CC: Gil Rockah Signed-off-by: Jarod Wilson --- src/perftest_parameters.c | 5 ++++- src/perftest_resources.c | 5 ++++- src/raw_ethernet_resources.c | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/perftest_parameters.c b/src/perftest_parameters.c index e316143..32ebea9 100755 --- a/src/perftest_parameters.c +++ b/src/perftest_parameters.c @@ -147,7 +147,10 @@ static int get_cache_line_size() if (fp == NULL) { return DEF_CACHE_LINE_SIZE; } - fgets(line,10,fp); + if (fgets(line,10,fp) == NULL) { + fclose(fp); + return DEF_CACHE_LINE_SIZE; + } size = atoi(line); fclose(fp); } diff --git a/src/perftest_resources.c b/src/perftest_resources.c index 4dc0705..91c6d1e 100755 --- a/src/perftest_resources.c +++ b/src/perftest_resources.c @@ -230,7 +230,10 @@ static void get_cpu_stats(struct perftest_parameters *duration_param,int stat_in int index=0; fp = fopen(file_name, "r"); if (fp != NULL) { - fgets(line,100,fp); + if (fgets(line,100,fp) == NULL) { + fclose(fp); + return; + } compress_spaces(line,line); index=get_n_word_string(line,tmp,index,2); /* skip first word */ duration_param->cpu_util_data.ustat[stat_index-1] = atoll(tmp); diff --git a/src/raw_ethernet_resources.c b/src/raw_ethernet_resources.c index d087cab..22e1bab 100755 --- a/src/raw_ethernet_resources.c +++ b/src/raw_ethernet_resources.c @@ -69,7 +69,10 @@ int check_flow_steering_support(char *dev_name) fp = fopen(file_name, "r"); if (fp == NULL) return 0; - fgets(line,4,fp); + if (fgets(line,4,fp) == NULL) { + fclose(fp); + return 0; + } int val = atoi(line); if (val >= 0) {