From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id C4CE5697C for ; Tue, 17 May 2016 10:37:11 +0200 (CEST) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id 169C52978D; Tue, 17 May 2016 10:35:35 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: marcinx.kerlin@intel.com Date: Tue, 17 May 2016 10:36:57 +0200 Message-Id: <1463474217-30875-1-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1463411889-22245-1-git-send-email-marcinx.kerlin@intel.com> References: <1463411889-22245-1-git-send-email-marcinx.kerlin@intel.com> Subject: [dpdk-dev] [PATCH v2] cmdline: check return value at initialization X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 May 2016 08:37:11 -0000 From: Marcin Kerlin The value returned by rdline_init() was not checked in cmdline_new(). On error, free the allocated memory and return NULL. This condition should not happen today, but it's safer to do the check in case rdline_init() is updated. Fixes: af75078fece3 ("first public release") Coverity ID 13204 Signed-off-by: Marcin Kerlin Signed-off-by: Olivier Matz --- Hi Marcin, I updated the commit log and title to be clearer. Regards, Olivier v1 -> v2 rework title and commit log lib/librte_cmdline/cmdline.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index c405878..a9c47be 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -130,6 +130,7 @@ struct cmdline * cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out) { struct cmdline *cl; + int ret; if (!ctx || !prompt) return NULL; @@ -142,8 +143,13 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out) cl->s_out = s_out; cl->ctx = ctx; - rdline_init(&cl->rdl, cmdline_write_char, - cmdline_valid_buffer, cmdline_complete_buffer); + ret = rdline_init(&cl->rdl, cmdline_write_char, cmdline_valid_buffer, + cmdline_complete_buffer); + if (ret != 0) { + free(cl); + return NULL; + } + cl->rdl.opaque = cl; cmdline_set_prompt(cl, prompt); rdline_newline(&cl->rdl, cl->prompt); -- 2.8.0.rc3