From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.92.18.49]) by mx.groups.io with SMTP id smtpd.web12.4131.1590001487305776152 for ; Wed, 20 May 2020 12:04:47 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@outlook.com header.s=selector1 header.b=A8meNo8c; spf=pass (domain: outlook.com, ip: 40.92.18.49, mailfrom: spbrogan@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c9Y6JU11xsMvwMc4JxPZ4EZWhgz56GBf6W0fCxAlEqDkwy40FXFEzK/Ff1ppUlwX2H32w9h983cDr7wFqss1eCgUT88v2EASEcVzthc1q37kdtPzFQO2tuF/pxtq5VDlVJx4QASk9izqMfJkZiQCyrt0o1AmDXaHqNPBas1a1PL1OdamYXzuHQBV6QEcx+V6AYLs1jTIVV2luqp+zTaF7lGvrbFAzDM7iE5XROE05Amp4GcP/k14LoskimHr0brmziYOk3qGe420mUTJxh5NFMqmPBWEUmD9Top/12ELRK9YV5ZIYhNJ0mV3pln5XP3xbkHmipy6SCPH8QjBuL+P2Q== 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=WQAyFvb5RmCSM2J4tqRS5s5QZ0bTZ670rFPrJ+REJ7I=; b=T7AH85Q3UzugXpb2ClQAoSjsXz43VoxWLafDRavIIS7r3dXQGjUIBfvSJISKkw34d+2iG9zwy0HdFm1bQYIB0Q4rrPr8bSkQi9FTz9RfyKzeR3hPCBpwrAIBAtz5H7FQo3Gq3EFqNh6l7Gbz0x6rIYfUzsvfGeNHXRh/prT69rQQRVfQ23hZ2vRvIQzoByOmj9hVULxqFs9iPa8ZA7I8RJrF9AIY1AyMLyvsEF6JI+eZCWn14bEnBBsrgzVpOmGPgV6Djtdd8TMUhyE5jMvgQIpLMFS7NIAhSWAeb1CsE3zf1djKycFzqau1aBA+xTMbyAD2Q692Tmw0Ht0Nv0YIlw== 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=WQAyFvb5RmCSM2J4tqRS5s5QZ0bTZ670rFPrJ+REJ7I=; b=A8meNo8ckoE92vHURl2lQ+lzFAfjaCZu1VLgkpsTfY9dCosNvbYFyXnEx7hWU+N7JoFsXDfDFFBvp1jKjpWdEFSbIyQjb52MEQ2ZuL+NzeqD3qrTX5u/CJHh7sZynruJwgDIX26DPz6HL3KdT6pVvtxxkCZjn+YG1KrnocPtiCU+nMfvphqio/ttZ0ivt8A8rCz3VfsqaBCmmDiYchH3GmntCm80lpmSAmP1lJpYXkQSXbUSvXf9SKnFNIdOX5v/pzruPLEPq2NWCq0mo4jYjM22Q6CqOkQAHWcC3eCd+wyFdqnbIatv2w/kVBosD45FCMR6mO4s7K+wAMVVkaRAUg== Received: from CO1NAM11FT059.eop-nam11.prod.protection.outlook.com (2a01:111:e400:3861::50) by CO1NAM11HT120.eop-nam11.prod.protection.outlook.com (2a01:111:e400:3861::229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.19; Wed, 20 May 2020 19:04:45 +0000 Received: from BN8PR07MB6962.namprd07.prod.outlook.com (2a01:111:e400:3861::46) by CO1NAM11FT059.mail.protection.outlook.com (2a01:111:e400:3861::160) 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 19:04:45 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:852DE660323ABF9F8768F52071CA02BB9624B7D99A66A0A7B1DDF6979B534851;UpperCasedChecksum:19C44888DA91F53D095B8CB153F42C5D0C0214CCEBCA2CBFE4BC5FB653C7950A;SizeAsReceived:9428;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 19:04:45 +0000 Subject: Re: [edk2-devel] [Patch v8 2/2] MdePkg/Test/BaseLib: Add SAFE_STRING_CONSTRAINT_CHECK unit test To: devel@edk2.groups.io, michael.d.kinney@intel.com Cc: Andrew Fish , Ard Biesheuvel , Bret Barkelew , "Brian J . Johnson" , Chasel Chiu , Jordan Justen , Laszlo Ersek , Leif Lindholm , Liming Gao , Marvin H?user , Vincent Zimmer , Zhichao Gao , Jiewen Yao , 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 12:04:41 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 In-Reply-To: <20200520030120.21576-3-michael.d.kinney@intel.com> X-ClientProxiedBy: CO2PR04CA0155.namprd04.prod.outlook.com (2603:10b6:104::33) To BN8PR07MB6962.namprd07.prod.outlook.com (2603:10b6:408:d6::11) Return-Path: spbrogan@outlook.com X-Microsoft-Original-Message-ID: <25368ca4-ef41-3d26-0da9-cc45e286118c@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.2.78] (50.47.113.221) by CO2PR04CA0155.namprd04.prod.outlook.com (2603:10b6:104::33) 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 19:04:43 +0000 X-Microsoft-Original-Message-ID: <25368ca4-ef41-3d26-0da9-cc45e286118c@outlook.com> X-TMN: [07g54pxh2FvTN2J7WepcwdPuklhTBMyk] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 513a3f80-6196-467b-19aa-08d7fcf0a8ce X-MS-TrafficTypeDiagnostic: CO1NAM11HT120: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Rb84YiT1r9hc1ryrdEZaek9cgAzCg0WqzERlvzgi/HPDTQUEgCwfZjtiqyayCWyz9V2yFpGrZ7liU6g430JHB/p7qIeC60DLLCQUK07vznoAYa7lSOBoSUPBtEwoV8H+UxfyolaVoGAL5ONPR+GqYoIFv2juW7SSYVlGDSFDmIUKIqgcotIPYQT6/HuEGJuSVhF2nAFXclwto3MdWqdrg== 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: IiQ7fJaYUcH+UItT+yFyAz8OAZ98h2wTGSYY/VTaA9usGlbPLxrgM7JkE+dbLxrFF8hsfmw0LzwdugmN/YYNmnr84WRgH9WgGI727MKxUYgK5xSycu8pz89bkm+SdRAfmA7UxRtcgJJ4M3DBD+PjCA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 513a3f80-6196-467b-19aa-08d7fcf0a8ce X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2020 19:04:45.2605 (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: CO1NAM11HT120 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit 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. > // >