From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: hao.a.wu@intel.com) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by groups.io with SMTP; Wed, 07 Aug 2019 22:56:11 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Aug 2019 22:56:10 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,360,1559545200"; d="scan'208";a="182496827" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by FMSMGA003.fm.intel.com with ESMTP; 07 Aug 2019 22:56:10 -0700 Received: from fmsmsx111.amr.corp.intel.com (10.18.116.5) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 7 Aug 2019 22:56:10 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx111.amr.corp.intel.com (10.18.116.5) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 7 Aug 2019 22:56:09 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.112]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.139]) with mapi id 14.03.0439.000; Thu, 8 Aug 2019 13:56:08 +0800 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "Kinney, Michael D" CC: "Justen, Jordan L" , Andrew Fish , "Ni, Ray" Subject: Re: [edk2-devel] [Patch V2 3/3] EmulatorPkg: Add -D DISABLE_NEW_DEPRECATED_INTERFACES Thread-Topic: [edk2-devel] [Patch V2 3/3] EmulatorPkg: Add -D DISABLE_NEW_DEPRECATED_INTERFACES Thread-Index: AQHVTZCoQh7le2m250KaBPfw65C06qbwvfzg Date: Thu, 8 Aug 2019 05:56:07 +0000 Message-ID: References: <20190808022556.18828-1-michael.d.kinney@intel.com> <20190808022556.18828-4-michael.d.kinney@intel.com> In-Reply-To: <20190808022556.18828-4-michael.d.kinney@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: hao.a.wu@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello Mike, With one typo mentioned below addressed, Reviewed-by: Hao A Wu > -----Original Message----- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of > Michael D Kinney > Sent: Thursday, August 08, 2019 10:26 AM > To: devel@edk2.groups.io > Cc: Justen, Jordan L; Andrew Fish; Ni, Ray > Subject: [edk2-devel] [Patch V2 3/3] EmulatorPkg: Add -D > DISABLE_NEW_DEPRECATED_INTERFACES >=20 > https://bugzilla.tianocore.org/show_bug.cgi?id=3D162 >=20 > Update EmulatorPkg specific modules and libraries to use > safe string functions in BaseLib and safe PcdSetxx() > functions in PcdLib. With these updates, the define > DISABLE_NEW_DEPRECATED_INTERFACES is enabled in the DSC > file. >=20 > Cc: Jordan Justen > Cc: Andrew Fish > Cc: Ray Ni > Signed-off-by: Michael D Kinney > --- > EmulatorPkg/EmuBusDriverDxe/EmuBusDriverDxe.c | 9 +- > EmulatorPkg/EmulatorPkg.dsc | 6 +- > EmulatorPkg/FlashMapPei/FlashMapPei.c | 8 +- > EmulatorPkg/Library/SmbiosLib/SmbiosLib.c | 4 +- > .../ThunkProtocolList/ThunkProtocolList.c | 11 +- > EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c | 8 +- > EmulatorPkg/Unix/Host/PosixFileSystem.c | 77 ++++++++---- > EmulatorPkg/Unix/Host/X11GraphicsWindow.c | 4 +- > EmulatorPkg/Win/Host/WinFileSystem.c | 116 ++++++++++++------ > 9 files changed, 169 insertions(+), 74 deletions(-) >=20 > diff --git a/EmulatorPkg/EmuBusDriverDxe/EmuBusDriverDxe.c > b/EmulatorPkg/EmuBusDriverDxe/EmuBusDriverDxe.c > index 0bf6e723a1..d8380f2be9 100644 > --- a/EmulatorPkg/EmuBusDriverDxe/EmuBusDriverDxe.c > +++ b/EmulatorPkg/EmuBusDriverDxe/EmuBusDriverDxe.c > @@ -1,7 +1,7 @@ > /** @file > Emu Bus driver >=20 > -Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
> +Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> Portions copyright (c) 2011, Apple Inc. All rights reserved. > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -256,7 +256,12 @@ EmuBusDriverBindingStart ( >=20 > EmuDevice->ControllerNameTable =3D NULL; >=20 > - StrnCpy (ComponentName, EmuIoThunk->ConfigString, sizeof > (ComponentName)/sizeof (CHAR16)); > + StrnCpyS ( > + ComponentName, > + sizeof (ComponentName) / sizeof (CHAR16), > + EmuIoThunk->ConfigString, > + sizeof (ComponentName) / sizeof (CHAR16) > + ); >=20 > EmuDevice->DevicePath =3D EmuBusCreateDevicePath ( > ParentDevicePath, > diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc > index 153da464f1..529adfe1fa 100644 > --- a/EmulatorPkg/EmulatorPkg.dsc > +++ b/EmulatorPkg/EmulatorPkg.dsc > @@ -408,10 +408,14 @@ [Components] > !include NetworkPkg/Network.dsc.inc >=20 > [BuildOptions] > + # > + # Disable deprecated APIs. > + # > + *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES > + > MSFT:DEBUG_*_*_CC_FLAGS =3D /Od /Oy- > MSFT:NOOPT_*_*_CC_FLAGS =3D /Od /Oy- >=20 > MSFT:*_*_*_DLINK_FLAGS =3D /ALIGN:4096 /FILEALIGN:4096 > /SUBSYSTEM:CONSOLE > MSFT:DEBUG_*_*_DLINK_FLAGS =3D > /EXPORT:InitializeDriver=3D$(IMAGE_ENTRY_POINT) /BASE:0x10000 > MSFT:NOOPT_*_*_DLINK_FLAGS =3D > /EXPORT:InitializeDriver=3D$(IMAGE_ENTRY_POINT) /BASE:0x10000 > - > diff --git a/EmulatorPkg/FlashMapPei/FlashMapPei.c > b/EmulatorPkg/FlashMapPei/FlashMapPei.c > index 2a468e43ac..7744065dd6 100644 > --- a/EmulatorPkg/FlashMapPei/FlashMapPei.c > +++ b/EmulatorPkg/FlashMapPei/FlashMapPei.c > @@ -1,7 +1,7 @@ > /*++ @file > PEIM to build GUIDed HOBs for platform specific flash map >=20 > -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
> +Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> Portions copyright (c) 2011, Apple Inc. All rights reserved. > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -69,9 +69,9 @@ Returns: > return Status; > } >=20 > - PcdSet64 (PcdFlashNvStorageVariableBase64, PcdGet64 > (PcdEmuFlashNvStorageVariableBase) + FdFixUp); > - PcdSet64 (PcdFlashNvStorageFtwWorkingBase64, PcdGet64 > (PcdEmuFlashNvStorageFtwWorkingBase) + FdFixUp); > - PcdSet64 (PcdFlashNvStorageFtwSpareBase64, PcdGet64 > (PcdEmuFlashNvStorageFtwSpareBase) + FdFixUp); > + PcdSet64S (PcdFlashNvStorageVariableBase64, PcdGet64 > (PcdEmuFlashNvStorageVariableBase) + FdFixUp); > + PcdSet64S (PcdFlashNvStorageFtwWorkingBase64, PcdGet64 > (PcdEmuFlashNvStorageFtwWorkingBase) + FdFixUp); > + PcdSet64S (PcdFlashNvStorageFtwSpareBase64, PcdGet64 > (PcdEmuFlashNvStorageFtwSpareBase) + FdFixUp); >=20 > return EFI_SUCCESS; > } > diff --git a/EmulatorPkg/Library/SmbiosLib/SmbiosLib.c > b/EmulatorPkg/Library/SmbiosLib/SmbiosLib.c > index 331122e200..3acbb23644 100644 > --- a/EmulatorPkg/Library/SmbiosLib/SmbiosLib.c > +++ b/EmulatorPkg/Library/SmbiosLib/SmbiosLib.c > @@ -4,7 +4,7 @@ >=20 >=20 > Copyright (c) 2012, Apple Inc. All rights reserved. > -Portitions Copyright (c) 2006 - 2012, Intel Corporation. All rights > reserved.
> +Portitions Copyright (c) 2006 - 2019, Intel Corporation. All rights > reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -223,7 +223,7 @@ SmbiosLibUpdateUnicodeString ( > if (Ascii =3D=3D NULL) { > return EFI_OUT_OF_RESOURCES; > } > - UnicodeStrToAsciiStr (String, Ascii); > + UnicodeStrToAsciiStrS (String, Ascii, StrSize (String)); >=20 > StringIndex =3D StringNumber; > Status =3D gSmbios->UpdateString (gSmbios, &SmbiosHandle, &StringInde= x, > Ascii); > diff --git a/EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.c > b/EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.c > index b7aacc851c..3a7b6d1ceb 100644 > --- a/EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.c > +++ b/EmulatorPkg/Library/ThunkProtocolList/ThunkProtocolList.c > @@ -2,7 +2,7 @@ > Emulator Thunk to abstract OS services from pure EFI code >=20 > Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.
> - Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved. > + Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved. >=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -37,6 +37,7 @@ AddThunkProtocol ( > IN BOOLEAN EmuBusDriver > ) > { > + UINTN Size; > CHAR16 *StartString; > CHAR16 *SubString; > UINTN Instance; > @@ -47,8 +48,12 @@ AddThunkProtocol ( > } >=20 > Instance =3D 0; > - StartString =3D AllocatePool (StrSize (ConfigString)); > - StrCpy (StartString, ConfigString); > + Size =3D StrSize (ConfigString); > + StartString =3D AllocatePool (Size); > + if (StartString =3D=3D NULL) { > + return EFI_OUT_OF_RESOURCES; > + } > + StrCpyS (StartString, Size / sizeof (CHAR16), ConfigString); > while (*StartString !=3D '\0') { >=20 > // > diff --git a/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c > b/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c > index e318a90740..18cb3831a4 100644 > --- a/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c > +++ b/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c > @@ -4,7 +4,7 @@ >=20 > Tested on Mac OS X. >=20 > -Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.
> +Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.
> Portitions copyright (c) 2011, Apple Inc. All rights reserved. >=20 > SPDX-License-Identifier: BSD-2-Clause-Patent > @@ -1016,7 +1016,11 @@ GetInterfaceMacAddr ( > goto Exit; > } >=20 > - UnicodeStrToAsciiStr (Private->Thunk->ConfigString, Private- > >InterfaceName); > + UnicodeStrToAsciiStrS ( > + Private->Thunk->ConfigString, > + Private->InterfaceName, > + StrSize (Private->Thunk->ConfigString) > + ); >=20 > Status =3D EFI_NOT_FOUND; > If =3D IfAddrs; > diff --git a/EmulatorPkg/Unix/Host/PosixFileSystem.c > b/EmulatorPkg/Unix/Host/PosixFileSystem.c > index 6ba3b59d7a..fc217d7a00 100644 > --- a/EmulatorPkg/Unix/Host/PosixFileSystem.c > +++ b/EmulatorPkg/Unix/Host/PosixFileSystem.c > @@ -127,7 +127,11 @@ PosixOpenVolume ( > if (PrivateFile->FileName =3D=3D NULL) { > goto Done; > } > - AsciiStrCpy (PrivateFile->FileName, Private->FilePath); > + AsciiStrCpyS ( > + PrivateFile->FileName, > + AsciiStrSize (Private->FilePath), > + Private->FilePath > + ); >=20 > PrivateFile->Signature =3D EMU_EFI_FILE_PRIVATE_SIGNATURE; > PrivateFile->Thunk =3D Private->Thunk; > @@ -377,7 +381,7 @@ PosixFileOpen ( > EFI_FILE_INFO *Info; > struct stat finfo; > int res; > - > + UINTN Size; >=20 > PrivateFile =3D EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); > PrivateRoot =3D EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS > (PrivateFile->SimpleFileSystem); > @@ -412,17 +416,18 @@ OpenRoot: >=20 > CopyMem (NewPrivateFile, PrivateFile, sizeof (EMU_EFI_FILE_PRIVATE)); >=20 > - NewPrivateFile->FileName =3D malloc (AsciiStrSize (PrivateFile->FileN= ame) + > 1 + StrLen (FileName) + 1); > + Size =3D AsciiStrSize (PrivateFile->FileName) + 1 + StrLen (FileName)= + 1; > + NewPrivateFile->FileName =3D malloc (Size); > if (NewPrivateFile->FileName =3D=3D NULL) { > goto Done; > } >=20 > if (*FileName =3D=3D L'\\') { > - AsciiStrCpy (NewPrivateFile->FileName, PrivateRoot->FilePath); > + AsciiStrCpyS (NewPrivateFile->FileName, Size, PrivateRoot->FilePath= ); > // Skip first '\'. > Src =3D FileName + 1; > } else { > - AsciiStrCpy (NewPrivateFile->FileName, PrivateFile->FileName); > + AsciiStrCpyS (NewPrivateFile->FileName, Size, PrivateFile->FileName= ); > Src =3D FileName; > } > Dst =3D NewPrivateFile->FileName + AsciiStrLen (NewPrivateFile->FileN= ame); > @@ -748,7 +753,7 @@ PosixFileRead ( > UINTN NameSize; > UINTN ResultSize; > CHAR8 *FullFileName; > - > + UINTN FullFileNameSize; >=20 > PrivateFile =3D EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); >=20 > @@ -798,15 +803,16 @@ PosixFileRead ( >=20 > *BufferSize =3D ResultSize; >=20 > - FullFileName =3D malloc (AsciiStrLen(PrivateFile->FileName) + 1 + Nam= eSize); > + FullFileNameSize =3D AsciiStrLen(PrivateFile->FileName) + 1 + NameSiz= e; > + FullFileName =3D malloc (FullFileNameSize); > if (FullFileName =3D=3D NULL) { > Status =3D EFI_OUT_OF_RESOURCES; > goto Done; > } >=20 > - AsciiStrCpy (FullFileName, PrivateFile->FileName); > - AsciiStrCat (FullFileName, "/"); > - AsciiStrCat (FullFileName, PrivateFile->Dirent->d_name); > + AsciiStrCpyS (FullFileName, FullFileNameSize, PrivateFile->FileName); > + AsciiStrCatS (FullFileName, FullFileNameSize, "/"); > + AsciiStrCatS (FullFileName, FullFileNameSize, PrivateFile->Dirent- > >d_name); > Status =3D UnixSimpleFileSystemFileInfo ( > PrivateFile, > FullFileName, > @@ -1017,7 +1023,11 @@ PosixFileGetInfo ( > FileSystemInfoBuffer->BlockSize =3D buf.f_bsize; >=20 >=20 > - StrCpy ((CHAR16 *) FileSystemInfoBuffer->VolumeLabel, PrivateRoot- > >VolumeLabel); > + StrCpyS ( > + (CHAR16 *) FileSystemInfoBuffer->VolumeLabel, > + (*BufferSize - SIZE_OF_EFI_FILE_SYSTEM_INFO) / sizeof (CHAR16), > + PrivateRoot->VolumeLabel > + ); > *BufferSize =3D SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot= - > >VolumeLabel); >=20 > } else if (CompareGuid (InformationType, > &gEfiFileSystemVolumeLabelInfoIdGuid)) { > @@ -1026,7 +1036,11 @@ PosixFileGetInfo ( > return EFI_BUFFER_TOO_SMALL; > } >=20 > - StrCpy ((CHAR16 *) Buffer, PrivateRoot->VolumeLabel); > + StrCpyS ( > + (CHAR16 *) Buffer, > + *BufferSize / sizeof (CHAR16), > + PrivateRoot->VolumeLabel > + ); > *BufferSize =3D StrSize (PrivateRoot->VolumeLabel); >=20 > } > @@ -1082,7 +1096,7 @@ PosixFileSetInfo ( > CHAR16 *UnicodeFilePtr; > int UnixStatus; > struct utimbuf Utime; > - > + UINTN Size; >=20 > PrivateFile =3D EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); > PrivateRoot =3D EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS > (PrivateFile->SimpleFileSystem); > @@ -1110,7 +1124,11 @@ PosixFileSetInfo ( > goto Done; > } >=20 > - StrCpy (PrivateRoot->VolumeLabel, NewFileSystemInfo->VolumeLabel); > + StrCpyS ( > + PrivateRoot->VolumeLabel, > + StrSize (NewFileSystemInfo->VolumeLabel) / sizeof (CHAR16), > + NewFileSystemInfo->VolumeLabel > + ); >=20 > Status =3D EFI_SUCCESS; > goto Done; > @@ -1125,7 +1143,11 @@ PosixFileSetInfo ( > goto Done; > } >=20 > - StrCpy (PrivateRoot->VolumeLabel, (CHAR16 *) Buffer); > + StrCpyS ( > + PrivateRoot->VolumeLabel, > + StrSize (PrivateRoot->VolumeLabel) / sizeof (CHAR16), > + (CHAR16 *) Buffer > + ); >=20 > Status =3D EFI_SUCCESS; > goto Done; > @@ -1183,18 +1205,23 @@ PosixFileSetInfo ( > goto Done; > } >=20 > - AsciiStrCpy (OldFileName, PrivateFile->FileName); > + AsciiStrCpyS ( > + OldFileName, > + AsciiStrSize (PrivateFile->FileName), > + PrivateFile->FileName > + ); >=20 > // > // Make full pathname from new filename and rootpath. > // > if (NewFileInfo->FileName[0] =3D=3D '\\') { > - NewFileName =3D malloc (AsciiStrLen (PrivateRoot->FilePath) + 1 + S= trLen > (NewFileInfo->FileName) + 1); > + Size =3D AsciiStrLen (PrivateRoot->FilePath) + 1 + StrLen (NewFileI= nfo- > >FileName) + 1; > + NewFileName =3D malloc (Size); > if (NewFileName =3D=3D NULL) { > goto Done; > } >=20 > - AsciiStrCpy (NewFileName, PrivateRoot->FilePath); > + AsciiStrCpyS (NewFileName, Size, PrivateRoot->FilePath); > AsciiFilePtr =3D NewFileName + AsciiStrLen(NewFileName); > UnicodeFilePtr =3D NewFileInfo->FileName + 1; > *AsciiFilePtr++ =3D'/'; > @@ -1204,7 +1231,7 @@ PosixFileSetInfo ( > goto Done; > } >=20 > - AsciiStrCpy (NewFileName, PrivateRoot->FilePath); > + AsciiStrCpyS (NewFileName, Size, PrivateRoot->FilePath); I think we cannot directly use 'Size' here. The 'Size' is valid for the "if (NewFileInfo->FileName[0] =3D=3D '\\') {..= .}" chunk, but its value is not right for the "else {...}" block. Best Regards, Hao Wu > AsciiFilePtr =3D NewFileName + AsciiStrLen(NewFileName); > if ((AsciiFilePtr[-1] !=3D '/') && (NewFileInfo->FileName[0] !=3D '= /')) { > // make sure there is a / between Root FilePath and NewFileInfo > Filename > @@ -1312,7 +1339,11 @@ PosixFileSetInfo ( > goto Done; > } >=20 > - AsciiStrCpy (PrivateFile->FileName, NewFileName); > + AsciiStrCpyS ( > + PrivateFile->FileName, > + AsciiStrSize (NewFileName), > + NewFileName > + ); > } else { > Status =3D EFI_DEVICE_ERROR; > goto Done; > @@ -1493,7 +1524,11 @@ PosixFileSystmeThunkOpen ( > free (Private); > return EFI_OUT_OF_RESOURCES; > } > - StrCpy (Private->VolumeLabel, L"EFI_EMULATED"); > + StrCpyS ( > + Private->VolumeLabel, > + StrSize (L"EFI_EMULATED") / sizeof (CHAR16), > + L"EFI_EMULATED" > + ); >=20 > Private->Signature =3D EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE; > Private->Thunk =3D This; > diff --git a/EmulatorPkg/Unix/Host/X11GraphicsWindow.c > b/EmulatorPkg/Unix/Host/X11GraphicsWindow.c > index 9d03c13011..5325a0e35b 100644 > --- a/EmulatorPkg/Unix/Host/X11GraphicsWindow.c > +++ b/EmulatorPkg/Unix/Host/X11GraphicsWindow.c > @@ -1,6 +1,6 @@ > /*++ @file >=20 > -Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
> +Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.
> Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent > @@ -957,7 +957,7 @@ X11GraphicsWindowOpen ( > XDefineCursor (Drv->display, Drv->win, XCreateFontCursor (Drv->displa= y, > XC_pirate)); >=20 > Drv->Title =3D malloc (StrSize (This->ConfigString)); > - UnicodeStrToAsciiStr (This->ConfigString, Drv->Title); > + UnicodeStrToAsciiStrS (This->ConfigString, Drv->Title, StrSize (This- > >ConfigString)); > XStoreName (Drv->display, Drv->win, Drv->Title); >=20 > // XAutoRepeatOff (Drv->display); > diff --git a/EmulatorPkg/Win/Host/WinFileSystem.c > b/EmulatorPkg/Win/Host/WinFileSystem.c > index da6595228d..aab926889e 100644 > --- a/EmulatorPkg/Win/Host/WinFileSystem.c > +++ b/EmulatorPkg/Win/Host/WinFileSystem.c > @@ -1,7 +1,7 @@ > /*++ @file > Support OS native directory access. >=20 > -Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
> +Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 > @@ -205,8 +205,14 @@ WinNtOpenVolume ( > goto Done; > } >=20 > - StrCpy (PrivateFile->FilePath, Private->FilePath); > - StrCpy (PrivateFile->FileName, PrivateFile->FilePath); > + StrCpyS (PrivateFile->FilePath, > + StrSize (Private->FilePath) / sizeof (CHAR16), > + Private->FilePath > + ); > + StrCpyS (PrivateFile->FileName, > + StrSize (Private->FilePath) / sizeof (CHAR16), > + PrivateFile->FilePath > + ); > PrivateFile->Signature =3D WIN_NT_EFI_FILE_PRIVATE_SIGNATURE; > PrivateFile->Thunk =3D Private->Thunk; > PrivateFile->SimpleFileSystem =3D This; > @@ -243,8 +249,8 @@ WinNtOpenVolume ( > if (TempFileName =3D=3D NULL) { > goto Done; > } > - StrCpy (TempFileName, PrivateFile->FilePath); > - StrCat (TempFileName, L"\\*"); > + StrCpyS (TempFileName, Size / sizeof (CHAR16), PrivateFile->FilePath)= ; > + StrCatS (TempFileName, Size / sizeof (CHAR16), L"\\*"); >=20 > PrivateFile->LHandle =3D FindFirstFile (TempFileName, &PrivateFile->F= indBuf); > FreePool (TempFileName); > @@ -362,7 +368,7 @@ GetNextFileNameToken ( > } else { > Offset =3D SlashPos - *FileName; > Token =3D AllocateZeroPool ((Offset + 1) * sizeof (CHAR16)); > - StrnCpy (Token, *FileName, Offset); > + StrnCpyS (Token, Offset + 1, *FileName, Offset); > // > // Point *FileName to the next character after L'\'. > // > @@ -496,7 +502,7 @@ WinNtFileOpen ( > if (TempFileName =3D=3D NULL) { > return EFI_OUT_OF_RESOURCES; > } > - StrCpy (TempFileName, FileName); > + StrCpyS (TempFileName, StrSize (FileName) / sizeof (CHAR16), FileName= ); > FileName =3D TempFileName; >=20 > if (FileName[StrLen (FileName) - 1] =3D=3D L'\\') { > @@ -548,9 +554,17 @@ WinNtFileOpen ( > } >=20 > if (PrivateFile->IsDirectoryPath) { > - StrCpy (NewPrivateFile->FilePath, PrivateFile->FileName); > + StrCpyS ( > + NewPrivateFile->FilePath, > + StrSize (PrivateFile->FileName) / sizeof (CHAR16), > + PrivateFile->FileName > + ); > } else { > - StrCpy (NewPrivateFile->FilePath, PrivateFile->FilePath); > + StrCpyS ( > + NewPrivateFile->FilePath, > + StrSize (PrivateFile->FileName) / sizeof (CHAR16), > + PrivateFile->FilePath > + ); > } >=20 > Size =3D StrSize (NewPrivateFile->FilePath); > @@ -563,17 +577,17 @@ WinNtFileOpen ( > } >=20 > if (*FileName =3D=3D L'\\') { > - StrCpy (NewPrivateFile->FileName, PrivateRoot->FilePath); > - StrCat (NewPrivateFile->FileName, L"\\"); > - StrCat (NewPrivateFile->FileName, FileName + 1); > + StrCpyS (NewPrivateFile->FileName, Size / sizeof (CHAR16), PrivateR= oot- > >FilePath); > + StrCatS (NewPrivateFile->FileName, Size / sizeof (CHAR16), L"\\"); > + StrCatS (NewPrivateFile->FileName, Size / sizeof (CHAR16), FileName= + 1); > } else { > - StrCpy (NewPrivateFile->FileName, NewPrivateFile->FilePath); > + StrCpyS (NewPrivateFile->FileName, Size / sizeof (CHAR16), > NewPrivateFile->FilePath); > if (StrCmp (FileName, L"") !=3D 0) { > // > // In case the filename becomes empty, especially after trimming = dots > and blanks > // > - StrCat (NewPrivateFile->FileName, L"\\"); > - StrCat (NewPrivateFile->FileName, FileName); > + StrCatS (NewPrivateFile->FileName, Size / sizeof (CHAR16), L"\\")= ; > + StrCatS (NewPrivateFile->FileName, Size / sizeof (CHAR16), FileNa= me); > } > } >=20 > @@ -657,7 +671,11 @@ WinNtFileOpen ( > goto Done; > } >=20 > - StrCpy (NewPrivateFile->FilePath, NewPrivateFile->FileName); > + StrCpyS ( > + NewPrivateFile->FilePath, > + StrSize (NewPrivateFile->FileName) / sizeof (CHAR16), > + NewPrivateFile->FileName > + ); > if (TempChar !=3D 0) { > *(RealFileName - 1) =3D TempChar; > } > @@ -715,7 +733,7 @@ WinNtFileOpen ( > goto Done; > } >=20 > - StrCpy (TempFileName, NewPrivateFile->FileName); > + StrCpyS (TempFileName, Size / sizeof (CHAR16), NewPrivateFile- > >FileName); >=20 > if ((OpenMode & EFI_FILE_MODE_CREATE)) { > // > @@ -769,7 +787,7 @@ WinNtFileOpen ( > // > // Find the first file under it > // > - StrCat (TempFileName, L"\\*"); > + StrCatS (TempFileName, Size / sizeof (CHAR16), L"\\*"); > NewPrivateFile->LHandle =3D FindFirstFile (TempFileName, > &NewPrivateFile->FindBuf); > FreePool (TempFileName); >=20 > @@ -1330,8 +1348,8 @@ WinNtFileSetPossition ( > goto Done; > } >=20 > - StrCpy (FileName, PrivateFile->FileName); > - StrCat (FileName, L"\\*"); > + StrCpyS (FileName, Size / sizeof (CHAR16), PrivateFile->FileName); > + StrCatS (FileName, Size / sizeof (CHAR16), L"\\*"); >=20 > if (PrivateFile->LHandle !=3D INVALID_HANDLE_VALUE) { > FindClose (PrivateFile->LHandle); > @@ -1599,7 +1617,11 @@ WinNtFileGetInfo ( > goto Done; > } >=20 > - StrCpy (DriveName, PrivateFile->FilePath); > + StrCpyS ( > + DriveName, > + (StrSize (PrivateFile->FilePath) + 1) / sizeof (CHAR16), > + PrivateFile->FilePath > + ); > for (Index =3D 0; DriveName[Index] !=3D 0 && DriveName[Index] !=3D = ':'; > Index++) { > ; > } > @@ -1664,7 +1686,11 @@ WinNtFileGetInfo ( > } > } >=20 > - StrCpy ((CHAR16 *)FileSystemInfoBuffer->VolumeLabel, PrivateRoot- > >VolumeLabel); > + StrCpyS ( > + (CHAR16 *)FileSystemInfoBuffer->VolumeLabel, > + (*BufferSize - SIZE_OF_EFI_FILE_SYSTEM_INFO) / sizeof (CHAR16), > + PrivateRoot->VolumeLabel > + ); > *BufferSize =3D SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot= - > >VolumeLabel); > Status =3D EFI_SUCCESS; > } > @@ -1676,7 +1702,11 @@ WinNtFileGetInfo ( > goto Done; > } >=20 > - StrCpy ((CHAR16 *)Buffer, PrivateRoot->VolumeLabel); > + StrCpyS ( > + (CHAR16 *)Buffer, > + *BufferSize / sizeof (CHAR16), > + PrivateRoot->VolumeLabel > + ); > *BufferSize =3D StrSize (PrivateRoot->VolumeLabel); > Status =3D EFI_SUCCESS; > } > @@ -1768,7 +1798,11 @@ WinNtFileSetInfo ( > goto Done; > } >=20 > - StrCpy (PrivateRoot->VolumeLabel, NewFileSystemInfo->VolumeLabel); > + StrCpyS ( > + PrivateRoot->VolumeLabel, > + StrSize (NewFileSystemInfo->VolumeLabel) / sizeof (CHAR16), > + NewFileSystemInfo->VolumeLabel > + ); >=20 > Status =3D EFI_SUCCESS; > goto Done; > @@ -1783,7 +1817,11 @@ WinNtFileSetInfo ( > goto Done; > } >=20 > - StrCpy (PrivateRoot->VolumeLabel, (CHAR16 *)Buffer); > + StrCpyS ( > + PrivateRoot->VolumeLabel, > + StrSize (PrivateRoot->VolumeLabel) / sizeof (CHAR16), > + (CHAR16 *)Buffer > + ); >=20 > Status =3D EFI_SUCCESS; > goto Done; > @@ -1852,7 +1890,11 @@ WinNtFileSetInfo ( > goto Done; > } >=20 > - StrCpy (OldFileName, PrivateFile->FileName); > + StrCpyS ( > + OldFileName, > + StrSize (PrivateFile->FileName) / sizeof (CHAR16), > + PrivateFile->FileName > + ); >=20 > // > // Make full pathname from new filename and rootpath. > @@ -1867,9 +1909,9 @@ WinNtFileSetInfo ( > goto Done; > } >=20 > - StrCpy (NewFileName, PrivateRoot->FilePath); > - StrCat (NewFileName, L"\\"); > - StrCat (NewFileName, NewFileInfo->FileName + 1); > + StrCpyS (NewFileName, Size / sizeof (CHAR16), PrivateRoot->FilePath= ); > + StrCatS (NewFileName, Size / sizeof (CHAR16), L"\\"); > + StrCatS (NewFileName, Size / sizeof (CHAR16), NewFileInfo->FileName= + > 1); > } else { > Size =3D StrSize (PrivateFile->FilePath); > Size +=3D StrSize (L"\\"); > @@ -1880,9 +1922,9 @@ WinNtFileSetInfo ( > goto Done; > } >=20 > - StrCpy (NewFileName, PrivateFile->FilePath); > - StrCat (NewFileName, L"\\"); > - StrCat (NewFileName, NewFileInfo->FileName); > + StrCpyS (NewFileName, Size / sizeof (CHAR16), PrivateFile->FilePath= ); > + StrCatS (NewFileName, Size / sizeof (CHAR16), L"\\"); > + StrCatS (NewFileName, Size / sizeof (CHAR16), NewFileInfo->FileName= ); > } >=20 > // > @@ -1990,13 +2032,13 @@ WinNtFileSetInfo ( > goto Done; > } >=20 > - StrCpy (PrivateFile->FileName, NewFileName); > + StrCpyS (PrivateFile->FileName, StrSize (NewFileName) / sizeof > (CHAR16), NewFileName); >=20 > Size =3D StrSize (NewFileName); > Size +=3D StrSize (L"\\*"); > TempFileName =3D AllocatePool (Size); >=20 > - StrCpy (TempFileName, NewFileName); > + StrCpyS (TempFileName, Size / sizeof (CHAR16), NewFileName); >=20 > if (!PrivateFile->IsDirectoryPath) { > PrivateFile->LHandle =3D CreateFile ( > @@ -2029,7 +2071,7 @@ WinNtFileSetInfo ( > NULL > ); >=20 > - StrCat (TempFileName, L"\\*"); > + StrCatS (TempFileName, Size / sizeof (CHAR16), L"\\*"); > PrivateFile->LHandle =3D FindFirstFile (TempFileName, &FindBuf)= ; >=20 > FreePool (TempFileName); > @@ -2048,7 +2090,7 @@ WinNtFileSetInfo ( > Size +=3D StrSize (L"\\*"); > TempFileName =3D AllocatePool (Size); >=20 > - StrCpy (TempFileName, OldFileName); > + StrCpyS (TempFileName, Size / sizeof (CHAR16), OldFileName); >=20 > if (!PrivateFile->IsDirectoryPath) { > PrivateFile->LHandle =3D CreateFile ( > @@ -2071,7 +2113,7 @@ WinNtFileSetInfo ( > NULL > ); >=20 > - StrCat (TempFileName, L"\\*"); > + StrCatS (TempFileName, Size / sizeof (CHAR16), L"\\*"); > PrivateFile->LHandle =3D FindFirstFile (TempFileName, &FindBuf)= ; > } >=20 > -- > 2.21.0.windows.1 >=20 >=20 >=20