From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.92.23.27]) by mx.groups.io with SMTP id smtpd.web10.863.1590005815702747563 for ; Wed, 20 May 2020 13:16:55 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@outlook.com header.s=selector1 header.b=dUUPBWaR; spf=pass (domain: outlook.com, ip: 40.92.23.27, mailfrom: spbrogan@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P9zKkbJfOoJHs0OgRXL6fqYEkWSDTvpg1wvtftZj1znUSnMh75ofUw8IGgJF6HJXUopDCXlJlcuNpexIGWvgyrQq9ZWghE6li/0uyE3+SCF/+sepm+RCYe91+6P2vAw7hsPHD4L/+SPIskqMwWFb8cCnL2iTDmkB8xrNaYvHtwIyU0Ef2j3Ju9cxgNdHMglS+c/ppwFNialgykd83ErawM8LR6iLQdyMZvfw/fEo28w6bakPCMx7BoLus/4sYbrOOmzdkkmuDi8Ry/7Y028+I5HLDDToK2xbLzfDFr2Fk8V/O3aMB8VuOMS9KveiutuPDekx/fZ/tCr0uNF/odtQSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qggG8+bwsuX6+Rbk4UfLFqW4Z8AMeN8MVT2NNfh6W48=; b=SbXL4HoCx/5Tl5CD9V7cL5HDcvyhIvz/dmbAOxaWQY9O1BVdoIDqkNYYIMDBd37hyjF4bsjcBlPHxDQ3pYMSbnISK7Z3tTHxr+QGoeeoi9Bmie/F0GDWBjXKM4BLSS+VzHBlLuRPU6F8i6IlGqIkAYd9/rHjisI5JISnVuXK8/kK5vbhVVErATzJylNggkBu+D84SHExzpIByGJ8wPqRyyhMrwDbZ2grTxsDOqWJSMmi6EUtRCed5UpF4Zyoi0vZYetv+ssfE/Kgp64zRrSjltlyX+p/SKVKZ2XtavQARiyoCE0Rl4i+tiNTirWAdQYWUsTl9+j8XlP7FBJrtQVPCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=outlook.com; dmarc=pass action=none header.from=outlook.com; dkim=pass header.d=outlook.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qggG8+bwsuX6+Rbk4UfLFqW4Z8AMeN8MVT2NNfh6W48=; b=dUUPBWaR5ErAII3q8hVakzsKG3lwjKmslQLfNlEVSyr4+CGW3qtEFZbQWXIswgVojD+RyqVju4KRcsDD8YHzm54pq6WOe42MiGeWl4fpCKTAzFUengt09Cj0tHAxvn5PmEhlXgQGeupnoPeZUTGYLtENtIeQ7QDtccLP/QrXec1qHGpZbMaWv/xD61opJqJepMMTF4rBZFuJG8UJsp47j5gtyOF2M+Y45/gNR3NFQ5nay+egswMPioDTm4Xe4DPL2e5pHFMeik4kW4j5jv08yk00+VIcPYlE1OZ6MJF597dndJaqcBfHyrdLmK6iSBDNz3y5cv6pd+OnlxIVNeJZaA== Received: from MW2NAM12FT049.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::51) by MW2NAM12HT004.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc65::98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11; Wed, 20 May 2020 20:16:53 +0000 Received: from BN8PR07MB6962.namprd07.prod.outlook.com (2a01:111:e400:fc65::45) by MW2NAM12FT049.mail.protection.outlook.com (2a01:111:e400:fc65::439) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.11 via Frontend Transport; Wed, 20 May 2020 20:16:53 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:EF0D068023DBA11007F6C0A10AE0B08F29FF591D458D7F2A4B29303CDBCB0A88;UpperCasedChecksum:60FBDEB4ECC8994C1066A0EE14CFFF6D3B43C7866337257B4FE13CEF869B3698;SizeAsReceived:9702;Count:50 Received: from BN8PR07MB6962.namprd07.prod.outlook.com ([fe80::edbc:7122:7dd9:1403]) by BN8PR07MB6962.namprd07.prod.outlook.com ([fe80::edbc:7122:7dd9:1403%9]) with mapi id 15.20.3000.034; Wed, 20 May 2020 20:16:53 +0000 Subject: Re: [edk2-devel] [Patch v8 2/2] MdePkg/Test/BaseLib: Add SAFE_STRING_CONSTRAINT_CHECK unit test To: "Kinney, Michael D" , "devel@edk2.groups.io" Cc: Andrew Fish , Ard Biesheuvel , Bret Barkelew , "Brian J . Johnson" , "Chiu, Chasel" , "Justen, Jordan L" , Laszlo Ersek , Leif Lindholm , "Gao, Liming" , Marvin H?user , "Zimmer, Vincent" , "Gao, Zhichao" , "Yao, Jiewen" , Vitaly Cheptsov References: <20200520030120.21576-1-michael.d.kinney@intel.com> <20200520030120.21576-3-michael.d.kinney@intel.com> From: "Sean" Message-ID: Date: Wed, 20 May 2020 13:16:50 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 In-Reply-To: X-ClientProxiedBy: MWHPR12CA0067.namprd12.prod.outlook.com (2603:10b6:300:103::29) To BN8PR07MB6962.namprd07.prod.outlook.com (2603:10b6:408:d6::11) Return-Path: spbrogan@outlook.com X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.2.78] (50.47.113.221) by MWHPR12CA0067.namprd12.prod.outlook.com (2603:10b6:300:103::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Wed, 20 May 2020 20:16:51 +0000 X-Microsoft-Original-Message-ID: X-TMN: [KJa8XLRWtXnMd0f/jl/Lrd7m9B4ghEBg] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 81644247-ce11-4a35-f071-08d7fcfabc5d X-MS-TrafficTypeDiagnostic: MW2NAM12HT004: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D9NyEcFMlDW/ZCJVZgU7sUE2ewMNLI96Nlo4NOwmgHonropEUh2YsqJXDZ49CLYp00rwRXskhA7AFycube1d8qfhDlIbXLruccjtCgEEtIcCkG3e81RSZZ2FCEAYnh/jS3A81I3cIy3Ha5twGu6GopIGaeYdLMy5idHk9y7oHkSBlnA/KZTMh2IZ5tk+P8NW2RDLc/l78jysIOrcWtPGwP4vwkv6zvRGlYXGpa2cgSYIIAtMcrsp3PKOxVPM+mH/ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:0;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR07MB6962.namprd07.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:;DIR:OUT;SFP:1901; X-MS-Exchange-AntiSpam-MessageData: W6/0Aigt8YZJNdt2uc3vU4PY6s0/8n1OP4+DhAo72b2S0bFNV7C97+kd64MHzW/B/emjhXl7ixi5IZqGecDfHWF8T/DPdEGCb5bhFZr57HUD1OV1dcs1d/qZhJFOC8Lia0u6fwbYGgcH3f2nFs0U+g== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81644247-ce11-4a35-f071-08d7fcfabc5d X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2020 20:16:53.0701 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2NAM12HT004 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Bug created. https://bugzilla.tianocore.org/show_bug.cgi?id=2729 thanks Sean On 5/20/2020 1:11 PM, Kinney, Michael D wrote: > Hi Sean, > > I agree that tis unit test can be reorganized a bit to support > unit tests for all APIs in BaseLib. > > Can you enter a BZ for this and we can work on cleaning this > up after the stable tag? > > Mike > >> -----Original Message----- >> From: devel@edk2.groups.io On >> Behalf Of Sean >> Sent: Wednesday, May 20, 2020 12:05 PM >> To: devel@edk2.groups.io; Kinney, Michael D >> >> Cc: Andrew Fish ; Ard Biesheuvel >> ; Bret Barkelew >> ; Brian J . Johnson >> ; Chiu, Chasel >> ; Justen, Jordan L >> ; Laszlo Ersek >> ; Leif Lindholm ; >> Gao, Liming ; Marvin H?user >> ; Zimmer, Vincent >> ; Gao, Zhichao >> ; Yao, Jiewen >> ; Vitaly Cheptsov >> >> Subject: Re: [edk2-devel] [Patch v8 2/2] >> MdePkg/Test/BaseLib: Add SAFE_STRING_CONSTRAINT_CHECK >> unit test >> >> Mike, >> >> I would have thought the SafeString tests would have >> gone in a different >> c file. Base64UnitTest.c seems by its title to be >> targeted at the >> base64 encode/decode test. >> >> Looking at this i do see that would require some >> restructuring as there >> is no BaseLibUnitTest.c file for the common test part. >> As the author of >> this test originally, I can see that i didn't set it up >> to scale to the >> entire baselib very well. Sorry. >> >> >> Thanks >> Sean >> >> >> >> >> On 5/19/2020 8:01 PM, Michael D Kinney wrote: >>> Use the safe string function StrCpyS() in BaseLib to >> test the >>> SAFE_STRING_CONSTRAINT_CHECK() macro. >>> >>> Cc: Andrew Fish >>> Cc: Ard Biesheuvel >>> Cc: Bret Barkelew >>> Cc: Brian J. Johnson >>> Cc: Chasel Chiu >>> Cc: Jordan Justen >>> Cc: Laszlo Ersek >>> Cc: Leif Lindholm >>> Cc: Liming Gao >>> Cc: Marvin H?user >>> Cc: Michael D Kinney >>> Cc: Vincent Zimmer >>> Cc: Zhichao Gao >>> Cc: Jiewen Yao >>> Cc: Vitaly Cheptsov >>> Signed-off-by: Michael D Kinney >> >>> --- >>> .../UnitTest/Library/BaseLib/Base64UnitTest.c | 85 >> +++++++++++++++++++ >>> 1 file changed, 85 insertions(+) >>> >>> diff --git >> a/MdePkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c >> b/MdePkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c >>> index 8952f9da6c..5aced69e0d 100644 >>> --- >> a/MdePkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c >>> +++ >> b/MdePkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c >>> @@ -290,6 +290,77 @@ RfcDecodeTest( >>> return UNIT_TEST_PASSED; >>> } >>> >>> +#define SOURCE_STRING L"Hello" >>> + >>> +STATIC >>> +UNIT_TEST_STATUS >>> +EFIAPI >>> +SafeStringContraintCheckTest ( >>> + IN UNIT_TEST_CONTEXT Context >>> + ) >>> +{ >>> + RETURN_STATUS Status; >>> + CHAR16 Destination[20]; >>> + >>> + // >>> + // Positive test case copy source unicode string >> to destination >>> + // >>> + Status = StrCpyS (Destination, sizeof >> (Destination) / sizeof (CHAR16), SOURCE_STRING); >>> + UT_ASSERT_NOT_EFI_ERROR (Status); >>> + UT_ASSERT_MEM_EQUAL (Destination, SOURCE_STRING, >> sizeof (SOURCE_STRING)); >>> + >>> + // >>> + // Positive test case with DestMax the same as >> Source size >>> + // >>> + Status = StrCpyS (Destination, sizeof >> (SOURCE_STRING) / sizeof (CHAR16), SOURCE_STRING); >>> + UT_ASSERT_NOT_EFI_ERROR (Status); >>> + UT_ASSERT_MEM_EQUAL (Destination, SOURCE_STRING, >> sizeof (SOURCE_STRING)); >>> + >>> + // >>> + // Negative test case with Destination NULL >>> + // >>> + Status = StrCpyS (NULL, sizeof (Destination) / >> sizeof (CHAR16), SOURCE_STRING); >>> + UT_ASSERT_STATUS_EQUAL (Status, >> RETURN_INVALID_PARAMETER); >>> + >>> + // >>> + // Negative test case with Source NULL >>> + // >>> + Status = StrCpyS (Destination, sizeof >> (Destination) / sizeof (CHAR16), NULL); >>> + UT_ASSERT_STATUS_EQUAL (Status, >> RETURN_INVALID_PARAMETER); >>> + >>> + // >>> + // Negative test case with DestMax too big >>> + // >>> + Status = StrCpyS (Destination, MAX_UINTN, >> SOURCE_STRING); >>> + UT_ASSERT_STATUS_EQUAL (Status, >> RETURN_INVALID_PARAMETER); >>> + >>> + // >>> + // Negative test case with DestMax 0 >>> + // >>> + Status = StrCpyS (Destination, 0, SOURCE_STRING); >>> + UT_ASSERT_STATUS_EQUAL (Status, >> RETURN_INVALID_PARAMETER); >>> + >>> + // >>> + // Negative test case with DestMax smaller than >> Source size >>> + // >>> + Status = StrCpyS (Destination, 1, SOURCE_STRING); >>> + UT_ASSERT_STATUS_EQUAL (Status, >> RETURN_BUFFER_TOO_SMALL); >>> + >>> + // >>> + // Negative test case with DestMax smaller than >> Source size by one character >>> + // >>> + Status = StrCpyS (Destination, sizeof >> (SOURCE_STRING) / sizeof (CHAR16) - 1, SOURCE_STRING); >>> + UT_ASSERT_STATUS_EQUAL (Status, >> RETURN_BUFFER_TOO_SMALL); >>> + >>> + // >>> + // Negative test case with DestMax smaller than >> Source size >>> + // >>> + Status = StrCpyS (Destination, sizeof >> (Destination) / sizeof (CHAR16), Destination); >>> + UT_ASSERT_STATUS_EQUAL (Status, >> RETURN_ACCESS_DENIED); >>> + >>> + return UNIT_TEST_PASSED; >>> +} >>> + >>> /** >>> Initialze the unit test framework, suite, and >> unit tests for the >>> Base64 conversion APIs of BaseLib and run the >> unit tests. >>> @@ -309,6 +380,7 @@ UnitTestingEntry ( >>> UNIT_TEST_FRAMEWORK_HANDLE Fw; >>> UNIT_TEST_SUITE_HANDLE b64EncodeTests; >>> UNIT_TEST_SUITE_HANDLE b64DecodeTests; >>> + UNIT_TEST_SUITE_HANDLE SafeStringTests; >>> >>> Fw = NULL; >>> >>> @@ -367,6 +439,19 @@ UnitTestingEntry ( >>> AddTestCase (b64DecodeTests, "Incorrectly placed >> padding character", "Error4", RfcDecodeTest, NULL, >> CleanUpB64TestContext, &mBasicDecodeError4); >>> AddTestCase (b64DecodeTests, "Too small of output >> buffer", "Error5", RfcDecodeTest, NULL, >> CleanUpB64TestContext, &mBasicDecodeError5); >>> >>> + // >>> + // Populate the safe string Unit Test Suite. >>> + // >>> + Status = CreateUnitTestSuite (&SafeStringTests, >> Fw, "Safe String", "BaseLib.SafeString", NULL, NULL); >>> + if (EFI_ERROR (Status)) { >>> + DEBUG ((DEBUG_ERROR, "Failed in >> CreateUnitTestSuite for SafeStringTests\n")); >>> + Status = EFI_OUT_OF_RESOURCES; >>> + goto EXIT; >>> + } >>> + >>> + // --------------Suite-----------Description------ >> --------Class Name----------Function--------Pre---Post- >> ------------------Context----------- >>> + AddTestCase (SafeStringTests, >> "SAFE_STRING_CONSTRAINT_CHECK", >> "SafeStringContraintCheckTest", >> SafeStringContraintCheckTest, NULL, NULL, NULL); >>> + >>> // >>> // Execute the tests. >>> // >>> >> >> >