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 0DE5037B4 for ; Mon, 22 Jan 2018 16:02:17 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jan 2018 07:02:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,396,1511856000"; d="scan'208";a="12242202" Received: from silpixa00381635.ir.intel.com (HELO silpixa00381635.ger.corp.intel.com) ([10.237.222.149]) by fmsmga008.fm.intel.com with ESMTP; 22 Jan 2018 07:02:15 -0800 From: Jasvinder Singh To: dev@dpdk.org Cc: jingjing.wu@intel.com, john.mcnamara@intel.com Date: Mon, 22 Jan 2018 15:15:04 +0000 Message-Id: <20180122151504.107427-1-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.9.3 Subject: [dpdk-dev] [PATCH] app/testpmd: fix dereference null return valiue 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: Mon, 22 Jan 2018 15:02:18 -0000 Malloc() function might return NULL due to insufficient space. Therefore, check for handling memory allocation failure is added. Coverity issue: 257039 Fixes: e63b50162aa3 ("app/testpmd: clean metering and policing commands") Signed-off-by: Jasvinder Singh --- app/test-pmd/cmdline_mtr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c index 96a851b..f908fb3 100644 --- a/app/test-pmd/cmdline_mtr.c +++ b/app/test-pmd/cmdline_mtr.c @@ -86,6 +86,8 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table) /* Allocate memory for dscp table */ dscp_table = (enum rte_mtr_color *)malloc(MAX_DSCP_TABLE_ENTRIES * sizeof(enum rte_mtr_color)); + if (dscp_table == NULL) + return -1; while (1) { if (strcmp(token, "G") == 0 || @@ -105,8 +107,10 @@ parse_dscp_table_entries(char *str, enum rte_mtr_color *dscp_table) break; token = strtok_r(str, PARSE_DELIMITER, &str); - if (token == NULL) + if (token == NULL) { + free(dscp_table); return -1; + } } return 0; } -- 2.9.3