提交 ba97238d 编写于 作者: V vit9696

OpenCore: Validate storage path lengths

上级 1c2d05c0
......@@ -48,7 +48,17 @@ OcAcpiAddTables (
continue;
}
UnicodeSPrint (FullPath, sizeof (FullPath), OPEN_CORE_ACPI_PATH "%a", TablePath);
Status = OcUnicodeSafeSPrint (FullPath, sizeof (FullPath), OPEN_CORE_ACPI_PATH "%a", TablePath);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_WARN,
"OC: Failed to fit ACPI path %s%a",
OPEN_CORE_ACPI_PATH,
TablePath
));
continue;
}
UnicodeUefiSlashes (FullPath);
TableData = OcStorageReadFileUnicode (Storage, FullPath, &TableDataLength);
......
......@@ -174,6 +174,7 @@ OcKernelLoadKextsAndReserve (
IN OC_GLOBAL_CONFIG *Config
)
{
EFI_STATUS Status;
UINT32 Index;
UINT32 ReserveSize;
CHAR8 *BundlePath;
......@@ -202,13 +203,24 @@ OcKernelLoadKextsAndReserve (
continue;
}
UnicodeSPrint (
Status = OcUnicodeSafeSPrint (
FullPath,
sizeof (FullPath),
OPEN_CORE_KEXT_PATH "%a\\%a",
BundlePath,
PlistPath
);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_WARN,
"OC: Failed to fit kext path %s%a\\%a",
OPEN_CORE_KEXT_PATH,
BundlePath,
PlistPath
));
Kext->Enabled = FALSE;
continue;
}
UnicodeUefiSlashes (FullPath);
......@@ -232,13 +244,26 @@ OcKernelLoadKextsAndReserve (
ExecutablePath = OC_BLOB_GET (&Kext->ExecutablePath);
if (ExecutablePath[0] != '\0') {
UnicodeSPrint (
Status = OcUnicodeSafeSPrint (
FullPath,
sizeof (FullPath),
OPEN_CORE_KEXT_PATH "%a\\%a",
BundlePath,
ExecutablePath
);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_WARN,
"OC: Failed to fit kext path %s%a\\%a",
OPEN_CORE_KEXT_PATH,
BundlePath,
ExecutablePath
));
Kext->Enabled = FALSE;
FreePool (Kext->PlistData);
Kext->PlistData = NULL;
continue;
}
UnicodeUefiSlashes (FullPath);
......@@ -257,6 +282,8 @@ OcKernelLoadKextsAndReserve (
Comment
));
Kext->Enabled = FALSE;
FreePool (Kext->PlistData);
Kext->PlistData = NULL;
continue;
}
}
......@@ -603,7 +630,12 @@ OcKernelProcessPrelinked (
continue;
}
AsciiSPrint (FullPath, sizeof (FullPath), "/Library/Extensions/%a", BundlePath);
Status = OcAsciiSafeSPrint (FullPath, sizeof (FullPath), "/Library/Extensions/%a", BundlePath);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "OC: Failed to fit kext path /Library/Extensions/%a", BundlePath));
continue;
}
if (Kext->ImageData != NULL) {
ExecutablePath = OC_BLOB_GET (&Kext->ExecutablePath);
} else {
......
......@@ -23,6 +23,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include <Library/OcAppleBootPolicyLib.h>
#include <Library/OcConsoleLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcStringLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
......@@ -84,15 +85,25 @@ OcToolLoadEntry (
OUT EFI_DEVICE_PATH_PROTOCOL **ParentFilePath OPTIONAL
)
{
EFI_STATUS Status;
CHAR16 ToolPath[OC_STORAGE_SAFE_PATH_MAX];
OC_STORAGE_CONTEXT *Storage;
UnicodeSPrint (
Status = OcUnicodeSafeSPrint (
ToolPath,
sizeof (ToolPath),
OPEN_CORE_TOOL_PATH "%s",
ChosenEntry->PathName
);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
"OC: Tool %s%s does not fit path!\n",
OPEN_CORE_TOOL_PATH,
ToolPath
));
return EFI_NOT_FOUND;
}
Storage = (OC_STORAGE_CONTEXT *) Context;
......
......@@ -109,12 +109,21 @@ OcLoadDrivers (
continue;
}
UnicodeSPrint (
Status = OcUnicodeSafeSPrint (
DriverPath,
sizeof (DriverPath),
OPEN_CORE_UEFI_DRIVER_PATH "%a",
OC_BLOB_GET (Config->Uefi.Drivers.Values[Index])
);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
"OC: Driver %s%a doex not fit path!\n",
OPEN_CORE_UEFI_DRIVER_PATH,
OC_BLOB_GET (Config->Uefi.Drivers.Values[Index])
));
continue;
}
Driver = OcStorageReadFileUnicode (Storage, DriverPath, &DriverSize);
if (Driver == NULL) {
......
......@@ -70,6 +70,7 @@ OcAudioAcquireFile (
OUT UINT32 *BufferSize
)
{
EFI_STATUS Status;
CHAR8 IndexPath[8];
CHAR16 FilePath[OC_STORAGE_SAFE_PATH_MAX];
OC_STORAGE_CONTEXT *Storage;
......@@ -94,13 +95,14 @@ OcAudioAcquireFile (
BaseType = "OCEFIAudio";
if (File > OcVoiceOverAudioFileIndexBase && File <= OcVoiceOverAudioFileIndexMax) {
AsciiSPrint (
Status = OcAsciiSafeSPrint (
IndexPath,
sizeof (IndexPath),
"%a%c",
File >= OcVoiceOverAudioFileIndexAlphabetical ? "Letter" : "",
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[File - OcVoiceOverAudioFileIndexBase]
);
ASSERT_EFI_ERROR (Status);
BasePath = IndexPath;
} else {
switch (File) {
......@@ -251,7 +253,7 @@ OcAudioAcquireFile (
}
if (Localised) {
UnicodeSPrint (
Status = OcUnicodeSafeSPrint (
FilePath,
sizeof (FilePath),
OPEN_CORE_AUDIO_PATH "%a_%a_%a.wav",
......@@ -259,9 +261,10 @@ OcAudioAcquireFile (
OcLanguageCodeToString (LanguageCode),
BasePath
);
ASSERT_EFI_ERROR (Status);
if (!OcStorageExistsFileUnicode (Context, FilePath)) {
UnicodeSPrint (
Status = OcUnicodeSafeSPrint (
FilePath,
sizeof (FilePath),
OPEN_CORE_AUDIO_PATH "%a_%a_%a.wav",
......@@ -269,15 +272,17 @@ OcAudioAcquireFile (
OcLanguageCodeToString (AppleVoiceOverLanguageEn),
BasePath
);
ASSERT_EFI_ERROR (Status);
}
} else {
UnicodeSPrint (
Status = OcUnicodeSafeSPrint (
FilePath,
sizeof (FilePath),
OPEN_CORE_AUDIO_PATH "%a_%a.wav",
BaseType,
BasePath
);
ASSERT_EFI_ERROR (Status);
}
DEBUG ((DEBUG_INFO, "OC: Wave %s was requested\n", FilePath));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册