public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: devel@edk2.groups.io
Cc: Jiewen Yao <jiewen.yao@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>,
	Oliver Smith-Denny <osde@linux.microsoft.com>
Subject: [Patch v3 08/12] SecurityPkg/Library/SecureBootVariableLib: Fix VS20xx 4122 errors
Date: Fri,  7 Apr 2023 15:20:46 -0700	[thread overview]
Message-ID: <20230407222051.1095-9-michael.d.kinney@intel.com> (raw)
In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com>

The unit test code for the SecureBootVariableLib is initializing
local variable structures in their declaration from other local
variables that are also initialized in their declaration.  ANSI C
does not allow this and error 4122 is generated on VS20xx compilers.

The test cases are updated to initialize the local structure
fields in C statements instead of their local variable declaration.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Oliver Smith-Denny <osde@linux.microsoft.com>
---
 .../UnitTest/SecureBootVariableLibUnitTest.c  | 170 +++++++++---------
 1 file changed, 83 insertions(+), 87 deletions(-)

diff --git a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariableLibUnitTest.c b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariableLibUnitTest.c
index 3a92d5d83457..e4cdc68bbb35 100644
--- a/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariableLibUnitTest.c
+++ b/SecurityPkg/Library/SecureBootVariableLib/UnitTest/SecureBootVariableLibUnitTest.c
@@ -351,10 +351,10 @@ SecureBootCreateDataFromInputSimple (
   UINTN                         SigListSize = 0;
   EFI_STATUS                    Status;
   UINT8                         TestData[] = { 0 };
-  SECURE_BOOT_CERTIFICATE_INFO  KeyInfo    = {
-    .Data     = TestData,
-    .DataSize = sizeof (TestData)
-  };
+  SECURE_BOOT_CERTIFICATE_INFO  KeyInfo;
+
+  KeyInfo.Data     = TestData;
+  KeyInfo.DataSize = sizeof (TestData);
 
   Status = SecureBootCreateDataFromInput (&SigListSize, &SigList, 1, &KeyInfo);
 
@@ -441,16 +441,12 @@ SecureBootCreateDataFromInputMultiple (
   UINT8                         TestData1[] = { 0 };
   UINT8                         TestData2[] = { 1, 2 };
   EFI_STATUS                    Status;
-  SECURE_BOOT_CERTIFICATE_INFO  KeyInfo[2] = {
-    {
-      .Data     = TestData1,
-      .DataSize = sizeof (TestData1)
-    },
-    {
-      .Data     = TestData2,
-      .DataSize = sizeof (TestData2)
-    }
-  };
+  SECURE_BOOT_CERTIFICATE_INFO  KeyInfo[2];
+
+  KeyInfo[0].Data     = TestData1;
+  KeyInfo[0].DataSize = sizeof (TestData1);
+  KeyInfo[1].Data     = TestData2;
+  KeyInfo[1].DataSize = sizeof (TestData2);
 
   Status = SecureBootCreateDataFromInput (&SigListSize, &SigList, 2, KeyInfo);
   UT_ASSERT_NOT_EFI_ERROR (Status);
@@ -1219,19 +1215,19 @@ SetSecureBootVariablesShouldComplete (
   UINT8                     PkDummy     = 0xFE;
   UINT8                     *Payload    = NULL;
   UINTN                     PayloadSize = sizeof (DbDummy);
-  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo = {
-    .DbPtr             = &DbDummy,
-    .DbSize            = sizeof (DbDummy),
-    .DbxPtr            = &DbxDummy,
-    .DbxSize           = sizeof (DbxDummy),
-    .DbtPtr            = &DbtDummy,
-    .DbtSize           = sizeof (DbtDummy),
-    .KekPtr            = &KekDummy,
-    .KekSize           = sizeof (KekDummy),
-    .PkPtr             = &PkDummy,
-    .PkSize            = sizeof (PkDummy),
-    .SecureBootKeyName = L"Food"
-  };
+  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo;
+
+  PayloadInfo.DbPtr             = &DbDummy;
+  PayloadInfo.DbSize            = sizeof (DbDummy);
+  PayloadInfo.DbxPtr            = &DbxDummy;
+  PayloadInfo.DbxSize           = sizeof (DbxDummy);
+  PayloadInfo.DbtPtr            = &DbtDummy;
+  PayloadInfo.DbtSize           = sizeof (DbtDummy);
+  PayloadInfo.KekPtr            = &KekDummy;
+  PayloadInfo.KekSize           = sizeof (KekDummy);
+  PayloadInfo.PkPtr             = &PkDummy;
+  PayloadInfo.PkSize            = sizeof (PkDummy);
+  PayloadInfo.SecureBootKeyName = L"Food";
 
   expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME, sizeof (EFI_SECURE_BOOT_MODE_NAME));
   expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid);
@@ -1385,11 +1381,11 @@ SetSecureBootVariablesShouldStopFailDBX (
   UINT8                     DbxDummy    = 0xBE;
   UINT8                     *Payload    = NULL;
   UINTN                     PayloadSize = sizeof (DbxDummy);
-  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo = {
-    .DbxPtr            = &DbxDummy,
-    .DbxSize           = sizeof (DbxDummy),
-    .SecureBootKeyName = L"Fail DBX"
-  };
+  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo;
+
+  PayloadInfo.DbxPtr            = &DbxDummy;
+  PayloadInfo.DbxSize           = sizeof (DbxDummy);
+  PayloadInfo.SecureBootKeyName = L"Fail DBX";
 
   expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME, sizeof (EFI_SECURE_BOOT_MODE_NAME));
   expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid);
@@ -1442,13 +1438,13 @@ SetSecureBootVariablesShouldStopFailDB (
   UINT8                     DbxDummy    = 0xBE;
   UINT8                     *Payload    = NULL;
   UINTN                     PayloadSize = sizeof (DbDummy);
-  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo = {
-    .DbPtr             = &DbDummy,
-    .DbSize            = sizeof (DbDummy),
-    .DbxPtr            = &DbxDummy,
-    .DbxSize           = sizeof (DbxDummy),
-    .SecureBootKeyName = L"Fail DB"
-  };
+  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo;
+
+  PayloadInfo.DbPtr             = &DbDummy;
+  PayloadInfo.DbSize            = sizeof (DbDummy);
+  PayloadInfo.DbxPtr            = &DbxDummy;
+  PayloadInfo.DbxSize           = sizeof (DbxDummy);
+  PayloadInfo.SecureBootKeyName = L"Fail DB";
 
   expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME, sizeof (EFI_SECURE_BOOT_MODE_NAME));
   expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid);
@@ -1516,15 +1512,15 @@ SetSecureBootVariablesShouldStopFailDBT (
   UINT8                     DbxDummy    = 0xBE;
   UINT8                     *Payload    = NULL;
   UINTN                     PayloadSize = sizeof (DbDummy);
-  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo = {
-    .DbPtr             = &DbDummy,
-    .DbSize            = sizeof (DbDummy),
-    .DbxPtr            = &DbxDummy,
-    .DbxSize           = sizeof (DbxDummy),
-    .DbtPtr            = &DbtDummy,
-    .DbtSize           = sizeof (DbtDummy),
-    .SecureBootKeyName = L"Fail DBT"
-  };
+  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo;
+
+  PayloadInfo.DbPtr             = &DbDummy;
+  PayloadInfo.DbSize            = sizeof (DbDummy);
+  PayloadInfo.DbxPtr            = &DbxDummy;
+  PayloadInfo.DbxSize           = sizeof (DbxDummy);
+  PayloadInfo.DbtPtr            = &DbtDummy;
+  PayloadInfo.DbtSize           = sizeof (DbtDummy);
+  PayloadInfo.SecureBootKeyName = L"Fail DBT";
 
   expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME, sizeof (EFI_SECURE_BOOT_MODE_NAME));
   expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid);
@@ -1608,19 +1604,19 @@ SetSecureBootVariablesShouldStopFailKEK (
   UINT8                     PkDummy     = 0xFE;
   UINT8                     *Payload    = NULL;
   UINTN                     PayloadSize = sizeof (DbDummy);
-  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo = {
-    .DbPtr             = &DbDummy,
-    .DbSize            = sizeof (DbDummy),
-    .DbxPtr            = &DbxDummy,
-    .DbxSize           = sizeof (DbxDummy),
-    .DbtPtr            = &DbtDummy,
-    .DbtSize           = sizeof (DbtDummy),
-    .KekPtr            = &KekDummy,
-    .KekSize           = sizeof (KekDummy),
-    .PkPtr             = &PkDummy,
-    .PkSize            = sizeof (PkDummy),
-    .SecureBootKeyName = L"Food"
-  };
+  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo;
+
+  PayloadInfo.DbPtr             = &DbDummy;
+  PayloadInfo.DbSize            = sizeof (DbDummy);
+  PayloadInfo.DbxPtr            = &DbxDummy;
+  PayloadInfo.DbxSize           = sizeof (DbxDummy);
+  PayloadInfo.DbtPtr            = &DbtDummy;
+  PayloadInfo.DbtSize           = sizeof (DbtDummy);
+  PayloadInfo.KekPtr            = &KekDummy;
+  PayloadInfo.KekSize           = sizeof (KekDummy);
+  PayloadInfo.PkPtr             = &PkDummy;
+  PayloadInfo.PkSize            = sizeof (PkDummy);
+  PayloadInfo.SecureBootKeyName = L"Food";
 
   expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME, sizeof (EFI_SECURE_BOOT_MODE_NAME));
   expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid);
@@ -1718,19 +1714,19 @@ SetSecureBootVariablesShouldStopFailPK (
   UINT8                     PkDummy     = 0xFE;
   UINT8                     *Payload    = NULL;
   UINTN                     PayloadSize = sizeof (DbDummy);
-  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo = {
-    .DbPtr             = &DbDummy,
-    .DbSize            = sizeof (DbDummy),
-    .DbxPtr            = &DbxDummy,
-    .DbxSize           = sizeof (DbxDummy),
-    .DbtPtr            = &DbtDummy,
-    .DbtSize           = sizeof (DbtDummy),
-    .KekPtr            = &KekDummy,
-    .KekSize           = sizeof (KekDummy),
-    .PkPtr             = &PkDummy,
-    .PkSize            = sizeof (PkDummy),
-    .SecureBootKeyName = L"Food"
-  };
+  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo;
+
+  PayloadInfo.DbPtr             = &DbDummy;
+  PayloadInfo.DbSize            = sizeof (DbDummy);
+  PayloadInfo.DbxPtr            = &DbxDummy;
+  PayloadInfo.DbxSize           = sizeof (DbxDummy);
+  PayloadInfo.DbtPtr            = &DbtDummy;
+  PayloadInfo.DbtSize           = sizeof (DbtDummy);
+  PayloadInfo.KekPtr            = &KekDummy;
+  PayloadInfo.KekSize           = sizeof (KekDummy);
+  PayloadInfo.PkPtr             = &PkDummy;
+  PayloadInfo.PkSize            = sizeof (PkDummy);
+  PayloadInfo.SecureBootKeyName = L"Food";
 
   expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME, sizeof (EFI_SECURE_BOOT_MODE_NAME));
   expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid);
@@ -1841,19 +1837,19 @@ SetSecureBootVariablesDBTOptional (
   UINT8                     PkDummy     = 0xFE;
   UINT8                     *Payload    = NULL;
   UINTN                     PayloadSize = sizeof (DbDummy);
-  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo = {
-    .DbPtr             = &DbDummy,
-    .DbSize            = sizeof (DbDummy),
-    .DbxPtr            = &DbxDummy,
-    .DbxSize           = sizeof (DbxDummy),
-    .DbtPtr            = NULL,
-    .DbtSize           = 0,
-    .KekPtr            = &KekDummy,
-    .KekSize           = sizeof (KekDummy),
-    .PkPtr             = &PkDummy,
-    .PkSize            = sizeof (PkDummy),
-    .SecureBootKeyName = L"Food"
-  };
+  SECURE_BOOT_PAYLOAD_INFO  PayloadInfo;
+
+  PayloadInfo.DbPtr             = &DbDummy;
+  PayloadInfo.DbSize            = sizeof (DbDummy);
+  PayloadInfo.DbxPtr            = &DbxDummy;
+  PayloadInfo.DbxSize           = sizeof (DbxDummy);
+  PayloadInfo.DbtPtr            = NULL;
+  PayloadInfo.DbtSize           = 0;
+  PayloadInfo.KekPtr            = &KekDummy;
+  PayloadInfo.KekSize           = sizeof (KekDummy);
+  PayloadInfo.PkPtr             = &PkDummy;
+  PayloadInfo.PkSize            = sizeof (PkDummy);
+  PayloadInfo.SecureBootKeyName = L"Food";
 
   expect_memory (MockGetVariable, VariableName, EFI_SECURE_BOOT_MODE_NAME, sizeof (EFI_SECURE_BOOT_MODE_NAME));
   expect_value (MockGetVariable, VendorGuid, &gEfiGlobalVariableGuid);
-- 
2.39.1.windows.1


  parent reply	other threads:[~2023-04-07 22:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-07 22:20 [Patch v3 00/12] Add gmock support for host-based unit testing Michael D Kinney
2023-04-07 22:20 ` [Patch v3 01/12] UnitTestFrameworkPkg: Add subhook submodule required for gmock Michael D Kinney
2023-04-07 22:20 ` [Patch v3 02/12] .pytool/CISettings.py: Add subhook submodule Michael D Kinney
2023-04-07 22:20 ` [Patch v3 03/12] UnitTestFrameworkPkg: Add gmock support to GoogleTestLib Michael D Kinney
2023-04-07 22:20 ` [Patch v3 04/12] UnitTestFrameworkPkg/ReadMe.md: Add gmock documentation Michael D Kinney
2023-04-07 22:20 ` [Patch v3 05/12] MdePkg: Add gmock examples Michael D Kinney
2023-04-07 22:20 ` [Patch v3 06/12] MdeModulePkg/Library/UefiSortLib: Add GoogleTestLib example Michael D Kinney
2023-04-07 22:20 ` [Patch v3 07/12] SecurityPkg: Add gmock example Michael D Kinney
2023-04-07 22:20 ` Michael D Kinney [this message]
2023-04-07 22:20 ` [Patch v3 09/12] SecurityPkg/Library/SecureBootVariableLib: HOST_APPLICATION IA32/X64 only Michael D Kinney
2023-04-07 22:20 ` [Patch v3 10/12] MdePkg/Library/BaseLib: " Michael D Kinney
2023-04-07 22:20 ` [Patch v3 11/12] MdeModulePkg: " Michael D Kinney
2023-04-10  1:16   ` 回复: [edk2-devel] " gaoliming
2023-04-07 22:20 ` [Patch v3 12/12] PrmPkg/Library: " Michael D Kinney
2023-04-08  2:41   ` Michael Kubacki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230407222051.1095-9-michael.d.kinney@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox