summaryrefslogtreecommitdiffstats
path: root/EmulatorPkg/Unix
diff options
context:
space:
mode:
authorMichael D Kinney <michael.d.kinney@intel.com>2019-08-06 17:10:03 -0700
committerMichael D Kinney <michael.d.kinney@intel.com>2019-08-19 09:49:54 -0700
commit9e3ab94dc871926392b35dcf44c72ea74b1dd134 (patch)
tree54b530f4fdf3650ad4b5c22fe7db7c0f212d116c /EmulatorPkg/Unix
parent50509ec66c7a23acee1aaedfb5fb63871ee9b522 (diff)
downloadedk2-9e3ab94dc871926392b35dcf44c72ea74b1dd134.tar.gz
edk2-9e3ab94dc871926392b35dcf44c72ea74b1dd134.tar.bz2
edk2-9e3ab94dc871926392b35dcf44c72ea74b1dd134.zip
EmulatorPkg: Add -D DISABLE_NEW_DEPRECATED_INTERFACES
https://bugzilla.tianocore.org/show_bug.cgi?id=162 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. Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Andrew Fish <afish@apple.com> Cc: Ray Ni <ray.ni@intel.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Hao A Wu <hao.a.wu@intel.com> Acked-by: Jordan Justen <jordan.l.justen@intel.com> Tested-by: Andrew Fish <afish@apple.com>
Diffstat (limited to 'EmulatorPkg/Unix')
-rw-r--r--EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c10
-rw-r--r--EmulatorPkg/Unix/Host/PosixFileSystem.c80
-rw-r--r--EmulatorPkg/Unix/Host/X11GraphicsWindow.c4
3 files changed, 67 insertions, 27 deletions
diff --git a/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c b/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c
index e318a90740..8d0eb0d197 100644
--- a/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c
+++ b/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c
@@ -4,7 +4,7 @@
Tested on Mac OS X.
-Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
Portitions copyright (c) 2011, Apple Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -242,7 +242,7 @@ EmuSnpStart (
//
// Associate our interface with this BPF file descriptor.
//
- AsciiStrCpy (BoundIf.ifr_name, Private->InterfaceName);
+ AsciiStrCpyS (BoundIf.ifr_name, sizeof (BoundIf.ifr_name), Private->InterfaceName);
if (ioctl (Private->BpfFd, BIOCSETIF, &BoundIf) < 0) {
goto DeviceErrorExit;
}
@@ -1016,7 +1016,11 @@ GetInterfaceMacAddr (
goto Exit;
}
- UnicodeStrToAsciiStr (Private->Thunk->ConfigString, Private->InterfaceName);
+ UnicodeStrToAsciiStrS (
+ Private->Thunk->ConfigString,
+ Private->InterfaceName,
+ StrSize (Private->Thunk->ConfigString)
+ );
Status = EFI_NOT_FOUND;
If = IfAddrs;
diff --git a/EmulatorPkg/Unix/Host/PosixFileSystem.c b/EmulatorPkg/Unix/Host/PosixFileSystem.c
index 6ba3b59d7a..0a618abcd8 100644
--- a/EmulatorPkg/Unix/Host/PosixFileSystem.c
+++ b/EmulatorPkg/Unix/Host/PosixFileSystem.c
@@ -127,7 +127,11 @@ PosixOpenVolume (
if (PrivateFile->FileName == NULL) {
goto Done;
}
- AsciiStrCpy (PrivateFile->FileName, Private->FilePath);
+ AsciiStrCpyS (
+ PrivateFile->FileName,
+ AsciiStrSize (Private->FilePath),
+ Private->FilePath
+ );
PrivateFile->Signature = EMU_EFI_FILE_PRIVATE_SIGNATURE;
PrivateFile->Thunk = Private->Thunk;
@@ -377,7 +381,7 @@ PosixFileOpen (
EFI_FILE_INFO *Info;
struct stat finfo;
int res;
-
+ UINTN Size;
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
PrivateRoot = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
@@ -412,17 +416,18 @@ OpenRoot:
CopyMem (NewPrivateFile, PrivateFile, sizeof (EMU_EFI_FILE_PRIVATE));
- NewPrivateFile->FileName = malloc (AsciiStrSize (PrivateFile->FileName) + 1 + StrLen (FileName) + 1);
+ Size = AsciiStrSize (PrivateFile->FileName) + 1 + StrLen (FileName) + 1;
+ NewPrivateFile->FileName = malloc (Size);
if (NewPrivateFile->FileName == NULL) {
goto Done;
}
if (*FileName == L'\\') {
- AsciiStrCpy (NewPrivateFile->FileName, PrivateRoot->FilePath);
+ AsciiStrCpyS (NewPrivateFile->FileName, Size, PrivateRoot->FilePath);
// Skip first '\'.
Src = FileName + 1;
} else {
- AsciiStrCpy (NewPrivateFile->FileName, PrivateFile->FileName);
+ AsciiStrCpyS (NewPrivateFile->FileName, Size, PrivateFile->FileName);
Src = FileName;
}
Dst = NewPrivateFile->FileName + AsciiStrLen (NewPrivateFile->FileName);
@@ -748,7 +753,7 @@ PosixFileRead (
UINTN NameSize;
UINTN ResultSize;
CHAR8 *FullFileName;
-
+ UINTN FullFileNameSize;
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
@@ -798,15 +803,16 @@ PosixFileRead (
*BufferSize = ResultSize;
- FullFileName = malloc (AsciiStrLen(PrivateFile->FileName) + 1 + NameSize);
+ FullFileNameSize = AsciiStrLen(PrivateFile->FileName) + 1 + NameSize;
+ FullFileName = malloc (FullFileNameSize);
if (FullFileName == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
- 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 = UnixSimpleFileSystemFileInfo (
PrivateFile,
FullFileName,
@@ -1017,7 +1023,11 @@ PosixFileGetInfo (
FileSystemInfoBuffer->BlockSize = buf.f_bsize;
- StrCpy ((CHAR16 *) FileSystemInfoBuffer->VolumeLabel, PrivateRoot->VolumeLabel);
+ StrCpyS (
+ (CHAR16 *) FileSystemInfoBuffer->VolumeLabel,
+ (*BufferSize - SIZE_OF_EFI_FILE_SYSTEM_INFO) / sizeof (CHAR16),
+ PrivateRoot->VolumeLabel
+ );
*BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);
} else if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
@@ -1026,7 +1036,11 @@ PosixFileGetInfo (
return EFI_BUFFER_TOO_SMALL;
}
- StrCpy ((CHAR16 *) Buffer, PrivateRoot->VolumeLabel);
+ StrCpyS (
+ (CHAR16 *) Buffer,
+ *BufferSize / sizeof (CHAR16),
+ PrivateRoot->VolumeLabel
+ );
*BufferSize = StrSize (PrivateRoot->VolumeLabel);
}
@@ -1082,7 +1096,7 @@ PosixFileSetInfo (
CHAR16 *UnicodeFilePtr;
int UnixStatus;
struct utimbuf Utime;
-
+ UINTN Size;
PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
PrivateRoot = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
@@ -1110,7 +1124,11 @@ PosixFileSetInfo (
goto Done;
}
- StrCpy (PrivateRoot->VolumeLabel, NewFileSystemInfo->VolumeLabel);
+ StrCpyS (
+ PrivateRoot->VolumeLabel,
+ StrSize (NewFileSystemInfo->VolumeLabel) / sizeof (CHAR16),
+ NewFileSystemInfo->VolumeLabel
+ );
Status = EFI_SUCCESS;
goto Done;
@@ -1125,7 +1143,11 @@ PosixFileSetInfo (
goto Done;
}
- StrCpy (PrivateRoot->VolumeLabel, (CHAR16 *) Buffer);
+ StrCpyS (
+ PrivateRoot->VolumeLabel,
+ StrSize (PrivateRoot->VolumeLabel) / sizeof (CHAR16),
+ (CHAR16 *) Buffer
+ );
Status = EFI_SUCCESS;
goto Done;
@@ -1183,28 +1205,34 @@ PosixFileSetInfo (
goto Done;
}
- AsciiStrCpy (OldFileName, PrivateFile->FileName);
+ AsciiStrCpyS (
+ OldFileName,
+ AsciiStrSize (PrivateFile->FileName),
+ PrivateFile->FileName
+ );
//
// Make full pathname from new filename and rootpath.
//
if (NewFileInfo->FileName[0] == '\\') {
- NewFileName = malloc (AsciiStrLen (PrivateRoot->FilePath) + 1 + StrLen (NewFileInfo->FileName) + 1);
+ Size = AsciiStrLen (PrivateRoot->FilePath) + 1 + StrLen (NewFileInfo->FileName) + 1;
+ NewFileName = malloc (Size);
if (NewFileName == NULL) {
goto Done;
}
- AsciiStrCpy (NewFileName, PrivateRoot->FilePath);
+ AsciiStrCpyS (NewFileName, Size, PrivateRoot->FilePath);
AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName);
UnicodeFilePtr = NewFileInfo->FileName + 1;
*AsciiFilePtr++ ='/';
} else {
- NewFileName = malloc (AsciiStrLen (PrivateFile->FileName) + 2 + StrLen (NewFileInfo->FileName) + 1);
+ Size = AsciiStrLen (PrivateFile->FileName) + 2 + StrLen (NewFileInfo->FileName) + 1;
+ NewFileName = malloc (Size);
if (NewFileName == NULL) {
goto Done;
}
- AsciiStrCpy (NewFileName, PrivateRoot->FilePath);
+ AsciiStrCpyS (NewFileName, Size, PrivateRoot->FilePath);
AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName);
if ((AsciiFilePtr[-1] != '/') && (NewFileInfo->FileName[0] != '/')) {
// make sure there is a / between Root FilePath and NewFileInfo Filename
@@ -1312,7 +1340,11 @@ PosixFileSetInfo (
goto Done;
}
- AsciiStrCpy (PrivateFile->FileName, NewFileName);
+ AsciiStrCpyS (
+ PrivateFile->FileName,
+ AsciiStrSize (NewFileName),
+ NewFileName
+ );
} else {
Status = EFI_DEVICE_ERROR;
goto Done;
@@ -1493,7 +1525,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"
+ );
Private->Signature = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;
Private->Thunk = 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
-Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>
Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -957,7 +957,7 @@ X11GraphicsWindowOpen (
XDefineCursor (Drv->display, Drv->win, XCreateFontCursor (Drv->display, XC_pirate));
Drv->Title = malloc (StrSize (This->ConfigString));
- UnicodeStrToAsciiStr (This->ConfigString, Drv->Title);
+ UnicodeStrToAsciiStrS (This->ConfigString, Drv->Title, StrSize (This->ConfigString));
XStoreName (Drv->display, Drv->win, Drv->Title);
// XAutoRepeatOff (Drv->display);