From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 7769F2C6C for ; Thu, 14 Apr 2016 13:59:15 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP; 14 Apr 2016 04:59:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,484,1455004800"; d="scan'208";a="954878712" Received: from gklab-246-025.igk.intel.com (HELO Sent) ([10.217.246.25]) by orsmga002.jf.intel.com with SMTP; 14 Apr 2016 04:59:12 -0700 Received: by Sent (sSMTP sendmail emulation); Thu, 14 Apr 2016 15:01:23 +0200 From: Daniel Mrzyglod To: dev@dpdk.org Cc: olivier.matz@6wind.com, Daniel Mrzyglod Date: Thu, 14 Apr 2016 15:01:19 +0200 Message-Id: <1460638879-45680-1-git-send-email-danielx.t.mrzyglod@intel.com> X-Mailer: git-send-email 2.5.5 Subject: [dpdk-dev] [PATCH] cmdline: fix unchecked return value 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: Thu, 14 Apr 2016 11:59:15 -0000 This patch is for checking if error values occurs. fix for coverity errors #13209 & #13195 If the function returns an error value, the error value may be mistaken for a normal value. In rdline_char_in: Value returned from a function is not checked for errors before being used Signed-off-by: Daniel Mrzyglod --- lib/librte_cmdline/cmdline_rdline.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/librte_cmdline/cmdline_rdline.c b/lib/librte_cmdline/cmdline_rdline.c index 1ef2258..e75a556 100644 --- a/lib/librte_cmdline/cmdline_rdline.c +++ b/lib/librte_cmdline/cmdline_rdline.c @@ -377,7 +377,10 @@ rdline_char_in(struct rdline *rdl, char c) case CMDLINE_KEY_CTRL_K: cirbuf_get_buf_head(&rdl->right, rdl->kill_buf, RDLINE_BUF_SIZE); rdl->kill_size = CIRBUF_GET_LEN(&rdl->right); - cirbuf_del_buf_head(&rdl->right, rdl->kill_size); + + if (cirbuf_del_buf_head(&rdl->right, rdl->kill_size) < 0) + return -EINVAL; + rdline_puts(rdl, vt100_clear_right); break; @@ -496,7 +499,10 @@ rdline_char_in(struct rdline *rdl, char c) vt100_init(&rdl->vt100); cirbuf_init(&rdl->left, rdl->left_buf, 0, RDLINE_BUF_SIZE); cirbuf_init(&rdl->right, rdl->right_buf, 0, RDLINE_BUF_SIZE); - cirbuf_add_buf_tail(&rdl->left, buf, strnlen(buf, RDLINE_BUF_SIZE)); + + if (cirbuf_add_buf_tail(&rdl->left, buf, strnlen(buf, RDLINE_BUF_SIZE)) < 0) + return -EINVAL; + rdline_redisplay(rdl); break; @@ -513,7 +519,10 @@ rdline_char_in(struct rdline *rdl, char c) vt100_init(&rdl->vt100); cirbuf_init(&rdl->left, rdl->left_buf, 0, RDLINE_BUF_SIZE); cirbuf_init(&rdl->right, rdl->right_buf, 0, RDLINE_BUF_SIZE); - cirbuf_add_buf_tail(&rdl->left, buf, strnlen(buf, RDLINE_BUF_SIZE)); + + if (cirbuf_add_buf_tail(&rdl->left, buf, strnlen(buf, RDLINE_BUF_SIZE)) < 0) + return -EINVAL; + rdline_redisplay(rdl); break; @@ -640,7 +649,9 @@ rdline_add_history(struct rdline * rdl, const char * buf) rdline_remove_old_history_item(rdl); } - cirbuf_add_buf_tail(&rdl->history, buf, len); + if (cirbuf_add_buf_tail(&rdl->history, buf, len) < 0) + return -EINVAL; + cirbuf_add_tail(&rdl->history, 0); return 0; -- 2.5.5