From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web12.6748.1590070400380135934 for ; Thu, 21 May 2020 07:13:21 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=iRJHzWzU; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: liming.gao@intel.com) IronPort-SDR: 5Vv/mx6aGWUEjNZi4/wqCpmiU3kZMmP4gl5tSMkp4qZRB2rcp+btU7SxRBt9YCunYvZhEc92ev aMaoBljt1KyQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2020 07:13:19 -0700 IronPort-SDR: 0iZtezI4i6xwsEmFqAHSrYckMxOakCQuZK8ICawPhI32BlmEtJZaZjhSshEP8ovF8NegBai6Au l/vZLZx79t+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,417,1583222400"; d="scan'208";a="440461687" Received: from orsmsx109.amr.corp.intel.com ([10.22.240.7]) by orsmga005.jf.intel.com with ESMTP; 21 May 2020 07:13:19 -0700 Received: from orsmsx156.amr.corp.intel.com (10.22.240.22) by ORSMSX109.amr.corp.intel.com (10.22.240.7) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 21 May 2020 07:13:19 -0700 Received: from ORSEDG002.ED.cps.intel.com (10.7.248.5) by ORSMSX156.amr.corp.intel.com (10.22.240.22) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 21 May 2020 07:13:18 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.169) by edgegateway.intel.com (134.134.137.101) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 21 May 2020 07:13:18 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SlnfyjKLi4jvD1Sna6Cgw17ltqfGmJk+AyCcYcZTWdIf9irq2aSoUwtCt5OjIvNx1VOM5ZbgPHRoEmf0ZH6D8H1KeBcGGgRwHEdGbHXQp3lT7uv6s9Jm/sYrXip+BXKvZPA0KoCcE3YUPsOkM6839lePwlj56X2OMSGv9L/ar2qGKUQvaYdWfOX+BSYZwqICEX0Rngwd+Mi226cXDHEv6Zk/SpaLoqGtEYdRRRLzEvWCbxNMwmk41tjEdYpIsgjTDm8kQOIFQAymu1zgfsebCoi4BPZlV0y01elf7S7oXEQXhATCKT+ZpNF9BaFvWN5grq8GuLH/72fAcWZ9w3q6Kg== 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=Ay+YnmFgqpLsVtXDPswE0CMhnQIHpcvhEV4vrIIe6vM=; b=fju62KR+1bOQZlqX39zyoh0Dxm4Y4W5as/GhiFlnOfN+EgW7M1NZyU3PVw8xWha7oFVGaFribjS6nRQfgxFZ+jI2zLKhIyOwy093nAj59VwnpONHSNNn1uOafBr2NPeWBOb9A6k+pE0Q5cDX33Co/wt2lHhiR2OQg4rz7PNFJsNOyCXZ/2R8bkwuG3x9sKDWaGTxfkRMM/yyZBwceE6WnIkRk571Ih3nWc4zarFfvp0PeiFKxfyKQV17sF7J/ezFCO9BwMuQ7Gcig7uyZLdeyG/zI4RjTmSANfIRV6+k6YQisSJUx1ORxAulxKt5kCmH+7xFnLio52D4JMPzZllc2Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ay+YnmFgqpLsVtXDPswE0CMhnQIHpcvhEV4vrIIe6vM=; b=iRJHzWzUC0WwfxvWzaNa1gr17qWtpUs0TxDgz/eXxECdZdRdSC6FCJD9dDq2JuxCly+A6CsiCe3FGA43o95EmD4l27l+lygpH1/GovDxS30D10ODmNDFuENyiFHo+bfOrZbyN5MBwZej71l+Ljo3hU+sUHyQughCjRDJKJYeF0Y= Received: from SN6PR11MB3197.namprd11.prod.outlook.com (2603:10b6:805:c5::23) by SN6PR11MB2989.namprd11.prod.outlook.com (2603:10b6:805:da::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.27; Thu, 21 May 2020 14:13:17 +0000 Received: from SN6PR11MB3197.namprd11.prod.outlook.com ([fe80::a551:8867:924a:7217]) by SN6PR11MB3197.namprd11.prod.outlook.com ([fe80::a551:8867:924a:7217%5]) with mapi id 15.20.3021.020; Thu, 21 May 2020 14:13:17 +0000 From: "Liming Gao" 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" , Marvin H?user , "Zimmer, Vincent" , "Gao, Zhichao" , "Yao, Jiewen" , Vitaly Cheptsov , Philippe Mathieu-Daude Subject: Re: [edk2-devel] [Patch v9 2/2] MdePkg/Test/BaseLib: Add SAFE_STRING_CONSTRAINT_CHECK unit test Thread-Topic: [edk2-devel] [Patch v9 2/2] MdePkg/Test/BaseLib: Add SAFE_STRING_CONSTRAINT_CHECK unit test Thread-Index: AQHWLuLJWSkJfu2BeEKGy/vlBLLF6aiyliEQ Date: Thu, 21 May 2020 14:13:17 +0000 Message-ID: References: <20200520201022.28196-1-michael.d.kinney@intel.com> <20200520201022.28196-3-michael.d.kinney@intel.com> In-Reply-To: <20200520201022.28196-3-michael.d.kinney@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.2.0.6 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.55.52.205] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5c84cb5b-c877-4a02-18e8-08d7fd911bb5 x-ms-traffictypediagnostic: SN6PR11MB2989: x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1751; x-forefront-prvs: 041032FF37 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: xxnYSNQ5C51dTmRsgVGGqZXgNsZrz6e8xWeiw7g4xps4sWYIIVbhQARIZJrL0ptIR/pmhOQ7wlu8CfxrsPGglAis5w1WCKeoosZawH88vepb+FeZ7CI5aZrMeIptiGVaOyqfxKmS+VX0atwFn0FvsQhCfDs9YcoWTuN79HyLyvfOvUETM8mlhD3dJjj5fF4pBJIw5rPFkd8zE172DfrSr5fbt2GqnYM+MOzkgQc7tKqL5kCVJL0VEd2SJyxFNAaJZmbMZbOzFRcIl16IXEiBFqkx6vW5b3Vvx2+MN5YI+IpJLEEKLkakwtTOrfngrWQr/oTzE1ndzlbAc97oDcbdW85B0tdx278xNb2ZLvsUlkQeF0apHF7xNSU+WLlAWOjowUYCwmMRKs+t4QYQF5a+w8ZfA9MVnp/lkLnogk8y3PWnv+m8eYJPfPgg8dDU7AUvmsG2FNzDM+CLMCkA6GVFzvGGWTKse/5d3jwK2GlnFIPPrjA5A26/uXoUMLxrNFUyI8TkJ7v4D9r+1uufVVihWg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR11MB3197.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(396003)(346002)(376002)(366004)(39860400002)(136003)(8936002)(186003)(54906003)(966005)(4326008)(55016002)(5660300002)(8676002)(478600001)(33656002)(9686003)(7416002)(6636002)(2906002)(86362001)(110136005)(26005)(64756008)(52536014)(7696005)(53546011)(6506007)(66446008)(66476007)(71200400001)(66946007)(76116006)(316002)(19627235002)(66556008);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: Blu/g0L4y5sEN5zJh75RAspckF8d9orHE0gW/XYsRhBdy4hJWobyhaW3iGdBXaluD+/vWcnI+Jog1foYSptJPVVGwcuu/796Wa5P5N7xvCam1y2U2/5LD9M5C8RQVkyJtzz3GJ7DWNFHHUkWEAxy9YS12RSZ2L39q0muM2Qc4RsnspXmi8V4GHjLhvQgo3Iz71EnXxQTOw9m5EXZlJ5OAeYLjtsiKDfHvNjeDtvq9lXN5kL3+ifN740OcmoTtCSUVODxZIViCwsAZdY8yadyCEvuzRxj/oKDFuDX0BLA2JHBTAvc3Q34pLFH4I+MEI459B6P8bxgQPfij14ylEWiXLQCnCAGVVx2Lp9/3MfVxrl3c3VUfZ5SgvscQoFlMMzRYqnG7Mthhl0xVOaS0OjB2nz8eug++IELQtbH/jCNwBEhf5r7ZVFOQVl4HJYLaO/oWySmxN0S/0mflyDXv/44KOzYC/PdXjx/Rjhqqi8YVunPnwrfKKyj8anGyHm+521O MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 5c84cb5b-c877-4a02-18e8-08d7fd911bb5 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 May 2020 14:13:17.1394 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ftb8EGOcGFpgkbjbOV/z2CYl/3LQmh2fvCSsY5ZC9FAvDiMctcx35SUZ1hUYgnVb/OoQ51E3Qfc4mYKTR1FFvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB2989 Return-Path: liming.gao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ack-by: Liming Gao > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Michael D= Kinney > Sent: Thursday, May 21, 2020 4:10 AM > To: 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 ; Philip= pe Mathieu-Daude > Subject: [edk2-devel] [Patch v9 2/2] MdePkg/Test/BaseLib: Add SAFE_STRIN= G_CONSTRAINT_CHECK unit test >=20 > Use the safe string function StrCpyS() in BaseLib to test the > SAFE_STRING_CONSTRAINT_CHECK() macro. >=20 > 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 > Reviewed-by: Philippe Mathieu-Daude > --- > .../UnitTest/Library/BaseLib/Base64UnitTest.c | 107 ++++++++++++++++++ > 1 file changed, 107 insertions(+) >=20 > diff --git a/MdePkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c b/Mde= Pkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c > index 8952f9da6c..2c4266491c 100644 > --- a/MdePkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c > +++ b/MdePkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c > @@ -290,6 +290,99 @@ RfcDecodeTest( > return UNIT_TEST_PASSED; > } >=20 > +#define SOURCE_STRING L"Hello" > + > +STATIC > +UNIT_TEST_STATUS > +EFIAPI > +SafeStringContraintCheckTest ( > + IN UNIT_TEST_CONTEXT Context > + ) > +{ > + RETURN_STATUS Status; > + CHAR16 Destination[20]; > + CHAR16 AllZero[20]; > + > + // > + // Zero buffer used to verify Destination is not modified > + // > + ZeroMem (AllZero, sizeof (AllZero)); > + > + // > + // Positive test case copy source unicode string to destination > + // > + ZeroMem (Destination, sizeof (Destination)); > + Status =3D StrCpyS (Destination, sizeof (Destination) / sizeof (CHAR1= 6), SOURCE_STRING); > + UT_ASSERT_NOT_EFI_ERROR (Status); > + UT_ASSERT_MEM_EQUAL (Destination, SOURCE_STRING, sizeof (SOURCE_STRIN= G)); > + > + // > + // Positive test case with DestMax the same as Source size > + // > + ZeroMem (Destination, sizeof (Destination)); > + Status =3D StrCpyS (Destination, sizeof (SOURCE_STRING) / sizeof (CHA= R16), SOURCE_STRING); > + UT_ASSERT_NOT_EFI_ERROR (Status); > + UT_ASSERT_MEM_EQUAL (Destination, SOURCE_STRING, sizeof (SOURCE_STRIN= G)); > + > + // > + // Negative test case with Destination NULL > + // > + ZeroMem (Destination, sizeof (Destination)); > + Status =3D StrCpyS (NULL, sizeof (Destination) / sizeof (CHAR16), SOU= RCE_STRING); > + UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER); > + UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero)); > + > + // > + // Negative test case with Source NULL > + // > + ZeroMem (Destination, sizeof (Destination)); > + Status =3D StrCpyS (Destination, sizeof (Destination) / sizeof (CHAR1= 6), NULL); > + UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER); > + UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero)); > + > + // > + // Negative test case with DestMax too big > + // > + ZeroMem (Destination, sizeof (Destination)); > + Status =3D StrCpyS (Destination, MAX_UINTN, SOURCE_STRING); > + UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER); > + UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero)); > + > + // > + // Negative test case with DestMax 0 > + // > + ZeroMem (Destination, sizeof (Destination)); > + Status =3D StrCpyS (Destination, 0, SOURCE_STRING); > + UT_ASSERT_STATUS_EQUAL (Status, RETURN_INVALID_PARAMETER); > + UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero)); > + > + // > + // Negative test case with DestMax smaller than Source size > + // > + ZeroMem (Destination, sizeof (Destination)); > + Status =3D StrCpyS (Destination, 1, SOURCE_STRING); > + UT_ASSERT_STATUS_EQUAL (Status, RETURN_BUFFER_TOO_SMALL); > + UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero)); > + > + // > + // Negative test case with DestMax smaller than Source size by one ch= aracter > + // > + ZeroMem (Destination, sizeof (Destination)); > + Status =3D StrCpyS (Destination, sizeof (SOURCE_STRING) / sizeof (CHA= R16) - 1, SOURCE_STRING); > + UT_ASSERT_STATUS_EQUAL (Status, RETURN_BUFFER_TOO_SMALL); > + UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero)); > + > + // > + // Negative test case with overlapping Destination and Source > + // > + ZeroMem (Destination, sizeof (Destination)); > + Status =3D StrCpyS (Destination, sizeof (Destination) / sizeof (CHAR1= 6), Destination); > + UT_ASSERT_STATUS_EQUAL (Status, RETURN_ACCESS_DENIED); > + UT_ASSERT_MEM_EQUAL (Destination, AllZero, sizeof (AllZero)); > + > + 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 +402,7 @@ UnitTestingEntry ( > UNIT_TEST_FRAMEWORK_HANDLE Fw; > UNIT_TEST_SUITE_HANDLE b64EncodeTests; > UNIT_TEST_SUITE_HANDLE b64DecodeTests; > + UNIT_TEST_SUITE_HANDLE SafeStringTests; >=20 > Fw =3D NULL; >=20 > @@ -367,6 +461,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); >=20 > + // > + // Populate the safe string Unit Test Suite. > + // > + Status =3D CreateUnitTestSuite (&SafeStringTests, Fw, "Safe String", = "BaseLib.SafeString", NULL, NULL); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for SafeStringT= ests\n")); > + Status =3D EFI_OUT_OF_RESOURCES; > + goto EXIT; > + } > + > + // --------------Suite-----------Description--------------Class Name-= ---------Function--------Pre---Post-------------------Context----------- > + AddTestCase (SafeStringTests, "SAFE_STRING_CONSTRAINT_CHECK", "SafeSt= ringContraintCheckTest", SafeStringContraintCheckTest, > NULL, NULL, NULL); > + > // > // Execute the tests. > // > -- > 2.21.0.windows.1 >=20 >=20 >=20