From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 985981BBBC for ; Fri, 27 Oct 2017 10:57:42 +0200 (CEST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP; 27 Oct 2017 01:57:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,304,1505804400"; d="scan'208";a="167791103" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by fmsmga005.fm.intel.com with ESMTP; 27 Oct 2017 01:57:39 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: john.mcnamara@intel.com Date: Fri, 27 Oct 2017 10:10:18 +0100 Message-Id: <20171027091018.146152-1-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 Subject: [dpdk-dev] [PATCH] app/testpmd: fix NULL pointer deref for traffic management CLI 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: Fri, 27 Oct 2017 08:57:43 -0000 Malloc() function might returns NULL when memory allocation fails due to insufficient space. Therefore, check for handling memory allocation failure is added. Coverity issue: 198442,198444 Fixes: 996cb153af06 ("app/testpmd: add commands for TM nodes and hierarchy commit") Signed-off-by: Jasvinder Singh --- app/test-pmd/cmdline_tm.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/test-pmd/cmdline_tm.c b/app/test-pmd/cmdline_tm.c index 964ce9d..b737f8a 100644 --- a/app/test-pmd/cmdline_tm.c +++ b/app/test-pmd/cmdline_tm.c @@ -1615,6 +1615,11 @@ static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result, shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * sizeof(uint32_t)); + if (shared_shaper_id == NULL) { + printf(" Memory not allocated for shared shapers (error)\n"); + return; + } + /* Parse multi shared shaper id string */ ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); if (ret) { @@ -1770,6 +1775,11 @@ static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result, shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * sizeof(uint32_t)); + if (shared_shaper_id == NULL) { + printf(" Memory not allocated for shared shapers (error)\n"); + return; + } + /* Parse multi shared shaper id string */ ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); if (ret) { -- 2.9.3