From patchwork Wed Jul 8 20:33:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 1325471 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B29x31n9Pz9s1x; Thu, 9 Jul 2020 06:33:09 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jtGkb-0001mF-C8; Wed, 08 Jul 2020 20:33:05 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jtGka-0001m9-84 for fwts-devel@lists.ubuntu.com; Wed, 08 Jul 2020 20:33:04 +0000 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jtGkZ-0001It-Ue; Wed, 08 Jul 2020 20:33:04 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] opal: add check for the number of regions Date: Wed, 8 Jul 2020 21:33:03 +0100 Message-Id: <20200708203303.1260528-1-colin.king@canonical.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" From: Colin Ian King Add a sanity check for the number of regions, the function fwts_dt_stringlist_count can return 0 or -ve values and this will cause issues with a later malloc. Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Ivan Hu --- src/opal/reserv_mem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/opal/reserv_mem.c b/src/opal/reserv_mem.c index f243fb2e..5c15a7fc 100644 --- a/src/opal/reserv_mem.c +++ b/src/opal/reserv_mem.c @@ -143,6 +143,11 @@ static int reserv_mem_limits_test(fwts_framework *fw) /* Get the number of memory reserved regions */ nr_regions = fwts_dt_stringlist_count(fw, fw->fdt, offset, "reserved-names"); + if (nr_regions < 0) { + fwts_failed(fw, LOG_LEVEL_MEDIUM, "DTNoRegions", + "DT No regions"); + return FWTS_ERROR; + } /* Check for the reservd-names property */ region_names = (const char *)fdt_getprop(fw->fdt, offset,