From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.28286.1679769952773908107 for ; Sat, 25 Mar 2023 11:45:53 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Oopc9COT; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: michael.d.kinney@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679769953; x=1711305953; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tvKeigmOKlnvrLB0QDentH7DBQQFsFrLcgHsMMMGwVA=; b=Oopc9COT2k3NLX9QHwC5VYVg7NkAkO+TFD3wfeMwYos8Z3sRsHA02bHf xs01p6BmXGoayO7cQlbISGTpLgT9DjVRIqBaNsCHSAAqNDj2EwCnrv4dq hz97nfwVXnz2QelrHtcBw7eyda1vJnc+ULduQocnSWMI0MRsmUUkLosWh mgKYwSGlusPHjlM0GutemmzyLPO8NGhiPqQcBKwAMgjN/6ouHjsEuOmNu mYyyH9uUj12oCietp838cjSUfQNtnsHDQH9mmteZgBCsZ8ekSLWxLXTcJ P/4AjDOkzpiBdU+BgxMJoyg35AOim8sPvo67Xa2KN4QX0cHSvABzURhRv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10660"; a="319655085" X-IronPort-AV: E=Sophos;i="5.98,291,1673942400"; d="scan'208";a="319655085" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2023 11:45:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10660"; a="685541416" X-IronPort-AV: E=Sophos;i="5.98,291,1673942400"; d="scan'208";a="685541416" Received: from mdkinney-mobl2.amr.corp.intel.com ([10.212.254.125]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2023 11:45:52 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Jiewen Yao , Jian J Wang Subject: [Patch 08/12] SecurityPkg/Library/SecureBootVariableLib: Fix VS20xx 4122 errors Date: Sat, 25 Mar 2023 11:45:36 -0700 Message-Id: <20230325184541.596-9-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.39.1.windows.1 In-Reply-To: <20230325184541.596-1-michael.d.kinney@intel.com> References: <20230325184541.596-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Jian J Wang Signed-off-by: Michael D Kinney --- .../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