From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web12.4892.1611221989595886776 for ; Thu, 21 Jan 2021 01:39:49 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: star.zeng@intel.com) IronPort-SDR: DUzSVkCLV8FpkoAibsGgFsXBhnIz8ChRNldxvMSrZo2K2JXofW7zBs7vUTrSDhp9YyJaYqdkHV rkObEQPbNBgw== X-IronPort-AV: E=McAfee;i="6000,8403,9870"; a="175736833" X-IronPort-AV: E=Sophos;i="5.79,363,1602572400"; d="scan'208";a="175736833" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2021 01:39:49 -0800 IronPort-SDR: czRdS1iBP7CuZ7x8jFZxJDHkbxe50sGl13tksBNZgAA8Lwa9pVAlLRWhm6qIx/1V0Y/rmL0KAD jKOGZ0wEhByQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,363,1602572400"; d="scan'208";a="385235569" Received: from shwdeopenlab103.ccr.corp.intel.com ([10.239.183.148]) by orsmga008.jf.intel.com with ESMTP; 21 Jan 2021 01:39:47 -0800 From: "Zeng, Star" To: devel@edk2.groups.io Cc: Star Zeng , Eric Dong , Ray Ni , Laszlo Ersek Subject: [PATCH] UefiCpuPkg RegisterCpuFeaturesLib: NumberOfCpus may be uninitialized Date: Thu, 21 Jan 2021 17:39:44 +0800 Message-Id: <20210121093944.1621-1-star.zeng@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit NumberOfCpus local variable in GetAcpiCpuData will be uninitialized when CpuS3DataDxe runs before DxeRegisterCpuFeaturesLib (linked by CpuFeaturesDxe) because there is no code to initialize it at (AcpiCpuData != NULL) execution path. The issue is exposed after cefad282fb31aff3e1a6dcbd368cbbffc3fce900 and 38ee7bafa72f58982f99ac6f61eef160f80bad69. There was negligence in that code review. One further topic may be "Could EDK2 CI be enhanced to catch this kind of uninitialized local variable case?". :) This patch fixes this regression issue. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Star Zeng --- .../Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c index 7bb92404027f..60daa5cc87f0 100644 --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c @@ -957,6 +957,7 @@ GetAcpiCpuData ( // // Allocate buffer for empty RegisterTable and PreSmmInitRegisterTable for all CPUs // + NumberOfCpus = AcpiCpuData->NumberOfCpus; TableSize = 2 * NumberOfCpus * sizeof (CPU_REGISTER_TABLE); RegisterTable = AllocatePages (EFI_SIZE_TO_PAGES (TableSize)); ASSERT (RegisterTable != NULL); -- 2.27.0.windows.1