From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 267B6A056B;
	Mon, 21 Nov 2022 21:41:13 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id E428542D50;
	Mon, 21 Nov 2022 21:40:40 +0100 (CET)
Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75])
 by mails.dpdk.org (Postfix) with ESMTP id 131F342D43
 for <dev@dpdk.org>; Mon, 21 Nov 2022 21:40:36 +0100 (CET)
Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by ams.source.kernel.org (Postfix) with ESMTPS id D7878B815D5
 for <dev@dpdk.org>; Mon, 21 Nov 2022 20:40:35 +0000 (UTC)
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D806C433B5;
 Mon, 21 Nov 2022 20:40:34 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
 s=k20201202; t=1669063234;
 bh=BPYN3i4UD0HJpTXVhiBL3FIbmMerNwTvZ3DLcv1+SaA=;
 h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
 b=Y0MhgmkeYcY5QLyKG2DpGUkXHBY6d7f9rkLZnQP2989A75IHtLNyOjzUYpS2oQFdx
 eWVGga1YeU6OeASKZtgxFguje1G2gu+1fWXlCm0v1KVoZQSivSbvIAyETcDBWRp7z6
 P7angG+BPGvBt7h69dQQ8oDZ27vK50PblC++2U4Mxnnx387z2fE/R7FlzopB0ANbM9
 H51Ay8Kipfe4dgHeKki5l2459yq09sZxJzkNSXd/5HsoJ7dGVfbfz/Rw2kVdi/DX0g
 sChym7Fe7Qu4TqTtzGn9eA4IqnafGLwjaCOi49F00Uuvodt3Rki48TOsauAHMVWv2O
 PcDthSNjGSEvQ==
From: okaya@kernel.org
To: dev@dpdk.org
Cc: Sinan Kaya <okaya@kernel.org>
Subject: [PATCH 07/11] malloc: check result of rte_fbarray_get
Date: Mon, 21 Nov 2022 15:40:13 -0500
Message-Id: <20221121204015.1135573-8-okaya@kernel.org>
X-Mailer: git-send-email 2.25.1
In-Reply-To: <20221121204015.1135573-1-okaya@kernel.org>
References: <20221121204015.1135573-1-okaya@kernel.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

From: Sinan Kaya <okaya@kernel.org>

In eal_memalloc_is_contig result of call to rte_fbarray_get
is dereferenced here and may be null.

Signed-off-by: Sinan Kaya <okaya@kernel.org>
---
 lib/eal/common/eal_common_memalloc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/eal/common/eal_common_memalloc.c b/lib/eal/common/eal_common_memalloc.c
index ab04479c1c..e7f4bede39 100644
--- a/lib/eal/common/eal_common_memalloc.c
+++ b/lib/eal/common/eal_common_memalloc.c
@@ -126,6 +126,8 @@ eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start,
 
 		/* skip first iteration */
 		ms = rte_fbarray_get(&msl->memseg_arr, start_seg);
+		if (!ms)
+			return false;
 		cur = ms->iova;
 		expected = cur + pgsz;
 
@@ -137,7 +139,7 @@ eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start,
 				cur_seg++, expected += pgsz) {
 			ms = rte_fbarray_get(&msl->memseg_arr, cur_seg);
 
-			if (ms->iova != expected)
+			if (ms && (ms->iova != expected))
 				return false;
 		}
 	}
-- 
2.25.1