Skip to content

Commit

Permalink
ocvalidate: Corrected max file path length
Browse files Browse the repository at this point in the history
  • Loading branch information
PMheart committed Feb 16, 2022
1 parent d4f90bd commit ae04256
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Utilities/ocvalidate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Utility to validate whether a `config.plist` matches requirements and convention
### Global Rules
- All entries must be set once only. Duplication is strictly prohibited.
- All strings (fields with plist `String` format) throughout the whole config only accept ASCII printable characters at most. Stricter rules may apply. For instance, some fields only accept specified values, as indicated in [Configuration.pdf](https://github.com/acidanthera/OpenCorePkg/blob/master/Docs/Configuration.pdf).
- All the paths relative to OpenCore root must be 128 bytes total including '\0' terminator.
- All the paths relative to OpenCore root must be less than or equal to 128 bytes (`OC_STORAGE_SAFE_PATH_MAX`) in total including '\0' terminator.
- Most binary patches must have `Find`, `Replace`, `Mask` (if used), and `ReplaceMask` (if used) identical size set. Also, `Find` requires `Mask` (or `Replace` requires `ReplaceMask`) to be active (set to non-zero) for corresponding bits.
- `MinKernel` and `MaxKernel` entries should follow conventions specified in [Configuration.pdf](https://github.com/acidanthera/OpenCorePkg/blob/master/Docs/Configuration.pdf). (TODO: Bring decent checks for this)
- `MinKernel` cannot be a value that is below macOS 10.4 (Darwin version 8).
Expand Down
12 changes: 10 additions & 2 deletions Utilities/ocvalidate/ValidateAcpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ CheckACPIAdd (
OC_ACPI_CONFIG *UserAcpi;
CONST CHAR8 *Path;
CONST CHAR8 *Comment;
UINTN AcpiAddSumSize;

ErrorCount = 0;
UserAcpi = &Config->Acpi;
Expand Down Expand Up @@ -88,8 +89,15 @@ CheckACPIAdd (
//
// Check the length of path relative to OC directory.
//
if (StrLen (OPEN_CORE_ACPI_PATH) + AsciiStrSize (Path) > OC_STORAGE_SAFE_PATH_MAX) {
DEBUG ((DEBUG_WARN, "ACPI->Add[%u]->Path is too long (should not exceed %u)!\n", Index, OC_STORAGE_SAFE_PATH_MAX));
AcpiAddSumSize = L_STR_LEN (OPEN_CORE_ACPI_PATH) + AsciiStrSize (Path);
if (AcpiAddSumSize > OC_STORAGE_SAFE_PATH_MAX) {
DEBUG ((
DEBUG_WARN,
"ACPI->Add[%u]->Path (length %u) is too long (should not exceed %u)!\n",
Index,
AsciiStrLen (Path),
OC_STORAGE_SAFE_PATH_MAX - L_STR_LEN (OPEN_CORE_ACPI_PATH)
));
++ErrorCount;
}
}
Expand Down
40 changes: 34 additions & 6 deletions Utilities/ocvalidate/ValidateKernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,16 @@ CheckKernelAdd (
OC_KERNEL_CONFIG *UserKernel;
CONST CHAR8 *Arch;
CONST CHAR8 *BundlePath;
UINTN BundlePathSumSize;
CONST CHAR8 *Comment;
CONST CHAR8 *ExecutablePath;
UINTN ExecutableFixedSize;
UINTN ExecutablePathSumSize;
CONST CHAR8 *MaxKernel;
CONST CHAR8 *MinKernel;
CONST CHAR8 *PlistPath;
UINTN PlistFixedSize;
UINTN PlistPathSumSize;
BOOLEAN IsLiluUsed;
BOOLEAN IsDisableLinkeditJettisonEnabled;
UINTN IndexKextInfo;
Expand Down Expand Up @@ -199,22 +204,45 @@ CheckKernelAdd (
//
// Check the length of path relative to OC directory.
//
if (StrLen (OPEN_CORE_KEXT_PATH) + AsciiStrSize (BundlePath) > OC_STORAGE_SAFE_PATH_MAX) {
DEBUG ((DEBUG_WARN, "Kernel->Add[%u]->BundlePath is too long (should not exceed %u)!\n", Index, OC_STORAGE_SAFE_PATH_MAX));
BundlePathSumSize = L_STR_LEN (OPEN_CORE_KEXT_PATH) + AsciiStrSize (BundlePath);
if (BundlePathSumSize > OC_STORAGE_SAFE_PATH_MAX) {
DEBUG ((
DEBUG_WARN,
"Kernel->Add[%u]->BundlePath (length %u) is too long (should not exceed %u)!\n",
Index,
AsciiStrLen (BundlePath),
OC_STORAGE_SAFE_PATH_MAX - L_STR_LEN (OPEN_CORE_KEXT_PATH)
));
++ErrorCount;
}
//
// There is one missing '\\' after the concatenation of BundlePath and ExecutablePath. Append one.
//
if (StrLen (OPEN_CORE_KEXT_PATH) + AsciiStrLen (BundlePath) + 1 + AsciiStrSize (ExecutablePath) > OC_STORAGE_SAFE_PATH_MAX) {
DEBUG ((DEBUG_WARN, "Kernel->Add[%u]->ExecutablePath is too long (should not exceed %u)!\n", Index, OC_STORAGE_SAFE_PATH_MAX));
ExecutableFixedSize = L_STR_LEN (OPEN_CORE_KEXT_PATH) + AsciiStrLen (BundlePath) + 1;
ExecutablePathSumSize = ExecutableFixedSize + AsciiStrSize (ExecutablePath);
if (ExecutablePathSumSize > OC_STORAGE_SAFE_PATH_MAX) {
DEBUG ((
DEBUG_WARN,
"Kernel->Add[%u]->ExecutablePath (length %u) is too long (should not exceed %u)!\n",
Index,
AsciiStrLen (ExecutablePath),
OC_STORAGE_SAFE_PATH_MAX - ExecutableFixedSize
));
++ErrorCount;
}
//
// There is one missing '\\' after the concatenation of BundlePath and PlistPath. Append one.
//
if (StrLen (OPEN_CORE_KEXT_PATH) + AsciiStrLen (BundlePath) + 1 + AsciiStrSize (PlistPath) > OC_STORAGE_SAFE_PATH_MAX) {
DEBUG ((DEBUG_WARN, "Kernel->Add[%u]->PlistPath is too long (should not exceed %u)!\n", Index, OC_STORAGE_SAFE_PATH_MAX));
PlistFixedSize = L_STR_LEN (OPEN_CORE_KEXT_PATH) + AsciiStrLen (BundlePath) + 1;
PlistPathSumSize = PlistFixedSize + AsciiStrSize (PlistPath);
if (PlistPathSumSize > OC_STORAGE_SAFE_PATH_MAX) {
DEBUG ((
DEBUG_WARN,
"Kernel->Add[%u]->PlistPath (length %u) is too long (should not exceed %u)!\n",
Index,
AsciiStrLen (PlistPath),
OC_STORAGE_SAFE_PATH_MAX - PlistFixedSize
));
++ErrorCount;
}

Expand Down
4 changes: 1 addition & 3 deletions Utilities/ocvalidate/ValidateMisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ CheckMiscBoot (
CONST CHAR8 *PickerVariant;
UINTN PVSumSize;
UINTN PVPathFixedSize;
UINTN MaxPickerVariantLen;
BOOLEAN IsPickerAudioAssistEnabled;
BOOLEAN IsAudioSupportEnabled;
CONST CHAR8 *LauncherOption;
Expand Down Expand Up @@ -262,12 +261,11 @@ CheckMiscBoot (
PVPathFixedSize = L_STR_LEN (OPEN_CORE_IMAGE_PATH) + 1 + L_STR_SIZE ("ExtAppleRecv10_15.icns");
PVSumSize = PVPathFixedSize + AsciiStrLen (PickerVariant);
if (PVSumSize > OC_STORAGE_SAFE_PATH_MAX) {
MaxPickerVariantLen = OC_STORAGE_SAFE_PATH_MAX - PVPathFixedSize;
DEBUG ((
DEBUG_WARN,
"Misc->Boot->PickerVariant (length %u) is too long (should not exceed %u)!\n",
AsciiStrLen (PickerVariant),
MaxPickerVariantLen
OC_STORAGE_SAFE_PATH_MAX - PVPathFixedSize
));
++ErrorCount;
}
Expand Down
12 changes: 10 additions & 2 deletions Utilities/ocvalidate/ValidateUefi.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ CheckUefiDrivers (
OC_UEFI_DRIVER_ENTRY *DriverEntry;
CONST CHAR8 *Comment;
CONST CHAR8 *Driver;
UINTN DriverSumSize;
BOOLEAN HasOpenRuntimeEfiDriver;
BOOLEAN HasOpenUsbKbDxeEfiDriver;
UINT32 IndexOpenUsbKbDxeEfiDriver;
Expand Down Expand Up @@ -335,8 +336,15 @@ CheckUefiDrivers (
//
// Check the length of path relative to OC directory.
//
if (StrLen (OPEN_CORE_UEFI_DRIVER_PATH) + AsciiStrSize (Driver) > OC_STORAGE_SAFE_PATH_MAX) {
DEBUG ((DEBUG_WARN, "UEFI->Drivers[%u] is too long (should not exceed %u)!\n", Index, OC_STORAGE_SAFE_PATH_MAX));
DriverSumSize = L_STR_LEN (OPEN_CORE_UEFI_DRIVER_PATH) + AsciiStrSize (Driver);
if (DriverSumSize > OC_STORAGE_SAFE_PATH_MAX) {
DEBUG ((
DEBUG_WARN,
"UEFI->Drivers[%u] (length %u) is too long (should not exceed %u)!\n",
Index,
AsciiStrLen (Driver),
OC_STORAGE_SAFE_PATH_MAX - L_STR_LEN (OPEN_CORE_UEFI_DRIVER_PATH)
));
++ErrorCount;
}

Expand Down

0 comments on commit ae04256

Please sign in to comment.