From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 591D04CC3 for ; Wed, 10 Apr 2019 13:24:56 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Apr 2019 04:24:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,332,1549958400"; d="scan'208";a="148041062" Received: from silpixa00399126.ir.intel.com (HELO silpixa00399126.ger.corp.intel.com) ([10.237.222.236]) by FMSMGA003.fm.intel.com with ESMTP; 10 Apr 2019 04:24:54 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: bernard.iremonger@intel.com, Bruce Richardson Date: Wed, 10 Apr 2019 12:24:47 +0100 Message-Id: <20190410112447.68386-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] reorder: add checks for invalid function inputs 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: Wed, 10 Apr 2019 11:24:56 -0000 For APIs which can return an error value, do sanity checking of the input parameters for NULL and return a suitable error value for those cases. NOTE: The drain function is currently omitting NULL checks too, but this function has no way to flag an error value, so checking in that case would simply mask problems. Reported-by: Bernard Iremonger Signed-off-by: Bruce Richardson --- lib/librte_reorder/rte_reorder.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/librte_reorder/rte_reorder.c b/lib/librte_reorder/rte_reorder.c index b15328b2e..3a4a1b0a0 100644 --- a/lib/librte_reorder/rte_reorder.c +++ b/lib/librte_reorder/rte_reorder.c @@ -222,6 +222,11 @@ rte_reorder_find_existing(const char *name) struct rte_tailq_entry *te; struct rte_reorder_list *reorder_list; + if (name == NULL) { + rte_errno = EINVAL; + return NULL; + } + reorder_list = RTE_TAILQ_CAST(rte_reorder_tailq.head, rte_reorder_list); rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK); @@ -295,8 +300,14 @@ int rte_reorder_insert(struct rte_reorder_buffer *b, struct rte_mbuf *mbuf) { uint32_t offset, position; - struct cir_buffer *order_buf = &b->order_buf; + struct cir_buffer *order_buf; + + if (b == NULL || mbuf == NULL) { + rte_errno = EINVAL; + return -1; + } + order_buf = &b->order_buf; if (!b->is_initialized) { b->min_seqn = mbuf->seqn; b->is_initialized = 1; -- 2.20.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 691ACA0096 for ; Wed, 10 Apr 2019 13:24:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3A5FC5589; Wed, 10 Apr 2019 13:24:57 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 591D04CC3 for ; Wed, 10 Apr 2019 13:24:56 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Apr 2019 04:24:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,332,1549958400"; d="scan'208";a="148041062" Received: from silpixa00399126.ir.intel.com (HELO silpixa00399126.ger.corp.intel.com) ([10.237.222.236]) by FMSMGA003.fm.intel.com with ESMTP; 10 Apr 2019 04:24:54 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: bernard.iremonger@intel.com, Bruce Richardson Date: Wed, 10 Apr 2019 12:24:47 +0100 Message-Id: <20190410112447.68386-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] reorder: add checks for invalid function inputs 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" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190410112447.p-E0P-s0H_EAZ6uHCRtQDlHCdxFlcoqdAeDSJeZxKz4@z> For APIs which can return an error value, do sanity checking of the input parameters for NULL and return a suitable error value for those cases. NOTE: The drain function is currently omitting NULL checks too, but this function has no way to flag an error value, so checking in that case would simply mask problems. Reported-by: Bernard Iremonger Signed-off-by: Bruce Richardson --- lib/librte_reorder/rte_reorder.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/librte_reorder/rte_reorder.c b/lib/librte_reorder/rte_reorder.c index b15328b2e..3a4a1b0a0 100644 --- a/lib/librte_reorder/rte_reorder.c +++ b/lib/librte_reorder/rte_reorder.c @@ -222,6 +222,11 @@ rte_reorder_find_existing(const char *name) struct rte_tailq_entry *te; struct rte_reorder_list *reorder_list; + if (name == NULL) { + rte_errno = EINVAL; + return NULL; + } + reorder_list = RTE_TAILQ_CAST(rte_reorder_tailq.head, rte_reorder_list); rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK); @@ -295,8 +300,14 @@ int rte_reorder_insert(struct rte_reorder_buffer *b, struct rte_mbuf *mbuf) { uint32_t offset, position; - struct cir_buffer *order_buf = &b->order_buf; + struct cir_buffer *order_buf; + + if (b == NULL || mbuf == NULL) { + rte_errno = EINVAL; + return -1; + } + order_buf = &b->order_buf; if (!b->is_initialized) { b->min_seqn = mbuf->seqn; b->is_initialized = 1; -- 2.20.1