From patchwork Fri Sep 15 11:33:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Wang X-Patchwork-Id: 28758 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 111D97CCD; Fri, 15 Sep 2017 13:46:24 +0200 (CEST) Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.217.80.70]) by dpdk.org (Postfix) with ESMTP id E5AE93238 for ; Fri, 15 Sep 2017 13:46:22 +0200 (CEST) Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 7FAA7A3E2D7F95CFBB19; Fri, 15 Sep 2017 19:46:21 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id v8FBk0Xu086755; Fri, 15 Sep 2017 19:46:08 +0800 (GMT-8) (envelope-from wang.yong19@zte.com.cn) Received: from localhost.localdomain.localdomain ([10.43.166.165]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017091519461375-2643729 ; Fri, 15 Sep 2017 19:46:13 +0800 From: Yong Wang To: thomas@monjalon.net Cc: dev@dpdk.org, Yong Wang Date: Fri, 15 Sep 2017 07:33:08 -0400 Message-Id: <1505475188-10681-1-git-send-email-wang.yong19@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-09-15 19:46:14, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2017-09-15 19:45:52, Serialize complete at 2017-09-15 19:45:52 X-MAIL: mse01.zte.com.cn v8FBk0Xu086755 Subject: [dpdk-dev] [PATCH] buildtools: add null point check for calloc 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" In func locate_pmd_entries(), pointer 'new' returned from call to func 'calloc' may be NULL. It is dereferenced without null point check. Signed-off-by: Yong Wang --- buildtools/pmdinfogen/pmdinfogen.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/buildtools/pmdinfogen/pmdinfogen.c b/buildtools/pmdinfogen/pmdinfogen.c index e73fc76..96ccbf3 100644 --- a/buildtools/pmdinfogen/pmdinfogen.c +++ b/buildtools/pmdinfogen/pmdinfogen.c @@ -327,6 +327,10 @@ static int locate_pmd_entries(struct elf_info *info) do { new = calloc(sizeof(struct pmd_driver), 1); + if (new == NULL) { + fprintf(stderr, "Failed to calloc memory\n"); + return -1; + } new->name_sym = find_sym_in_symtab(info, "this_pmd_name", last); last = new->name_sym; if (!new->name_sym) @@ -408,7 +412,8 @@ int main(int argc, char **argv) } parse_elf(&info, argv[1]); - locate_pmd_entries(&info); + if (locate_pmd_entries(&info) < 0) + exit(1); if (info.drivers) { output_pmd_info_string(&info, argv[2]);