From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 73F821B471 for ; Thu, 12 Jul 2018 12:49:52 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jul 2018 03:49:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,342,1526367600"; d="scan'208";a="74206032" Received: from rhorton-mobl1.ger.corp.intel.com (HELO FC23.ir.intel.com) ([163.33.179.30]) by orsmga002.jf.intel.com with ESMTP; 12 Jul 2018 03:49:49 -0700 From: Remy Horton To: dev@dpdk.org Date: Thu, 12 Jul 2018 11:49:48 +0100 Message-Id: <20180712104948.3113-1-remy.horton@intel.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180702132152.6135-1-remy.horton@intel.com> Subject: [dpdk-dev] [PATCH v2] lib/bitratestats: add NULL sanity checks X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jul 2018 10:49:52 -0000 If rte_stats_bitrate_reg() or rte_stats_bitrate_calc() are passed NULL as the parameter for the stats structure, the result is a crash. Fixed by adding a sanity check that makes sure the passed-in pointer is not NULL. Fixes: 2ad7ba9a6567 ("bitrate: add bitrate statistics library") Signed-off-by: Remy Horton --- lib/librte_bitratestats/rte_bitrate.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/librte_bitratestats/rte_bitrate.c b/lib/librte_bitratestats/rte_bitrate.c index 964e3c3..c4b28f6 100644 --- a/lib/librte_bitratestats/rte_bitrate.c +++ b/lib/librte_bitratestats/rte_bitrate.c @@ -47,6 +47,9 @@ rte_stats_bitrate_reg(struct rte_stats_bitrates *bitrate_data) }; int return_value; + if (bitrate_data == NULL) + return -EINVAL; + return_value = rte_metrics_reg_names(&names[0], ARRAY_SIZE(names)); if (return_value >= 0) bitrate_data->id_stats_set = return_value; @@ -65,6 +68,9 @@ rte_stats_bitrate_calc(struct rte_stats_bitrates *bitrate_data, const int64_t alpha_percent = 20; uint64_t values[6]; + if (bitrate_data == NULL) + return -EINVAL; + ret_code = rte_eth_stats_get(port_id, ð_stats); if (ret_code != 0) return ret_code; -- 2.9.5