Skip to content

Commit 508397d

Browse files
committed
some null checks as in original
Signed-off-by: SergeySlice <sergey.slice@gmail.com>
1 parent 87b4e64 commit 508397d

5 files changed

Lines changed: 145 additions & 29 deletions

File tree

Include/Acidanthera/Library/OcAppleKernelLib.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ PrelinkedReserveKextSize (
868868
@param[in,out] ExecutablePath Kext executable path (e.g. Contents/MacOS/mykext), optional.
869869
@param[in,out] Executable Kext executable, optional.
870870
@param[in] ExecutableSize Kext executable size, optional.
871+
@param[out] BundleVersion Kext bundle version, optionally set on request.
871872
872873
@return EFI_SUCCESS on success.
873874
**/
@@ -880,7 +881,8 @@ PrelinkedInjectKext (
880881
IN UINT32 InfoPlistSize,
881882
IN CONST CHAR8 *ExecutablePath OPTIONAL,
882883
IN OUT CONST UINT8 *Executable OPTIONAL,
883-
IN UINT32 ExecutableSize OPTIONAL
884+
IN UINT32 ExecutableSize OPTIONAL,
885+
OUT CONST CHAR8 **BundleVersion OPTIONAL
884886
);
885887

886888
/**
@@ -1257,6 +1259,7 @@ CachelessContextFree (
12571259
@param[in] InfoPlistSize Kext Info.plist size.
12581260
@param[in] Executable Kext executable, optional.
12591261
@param[in] ExecutableSize Kext executable size, optional.
1262+
@param[out] BundleVersion Kext bundle version, optionally set on request.
12601263
12611264
@return EFI_SUCCESS on success.
12621265
**/
@@ -1266,7 +1269,8 @@ CachelessContextAddKext (
12661269
IN CONST CHAR8 *InfoPlist,
12671270
IN UINT32 InfoPlistSize,
12681271
IN CONST UINT8 *Executable OPTIONAL,
1269-
IN UINT32 ExecutableSize OPTIONAL
1272+
IN UINT32 ExecutableSize OPTIONAL,
1273+
OUT CONST CHAR8 **BundleVersion OPTIONAL
12701274
);
12711275

12721276
/**
@@ -1484,6 +1488,7 @@ MkextReserveKextSize (
14841488
@param[in] InfoPlistSize Kext Info.plist size.
14851489
@param[in,out] Executable Kext executable, optional.
14861490
@param[in] ExecutableSize Kext executable size, optional.
1491+
@param[out] BundleVersion Kext bundle version, optionally set on request.
14871492
14881493
@return EFI_SUCCESS on success.
14891494
**/
@@ -1495,7 +1500,8 @@ MkextInjectKext (
14951500
IN CONST CHAR8 *InfoPlist,
14961501
IN UINT32 InfoPlistSize,
14971502
IN UINT8 *Executable OPTIONAL,
1498-
IN UINT32 ExecutableSize OPTIONAL
1503+
IN UINT32 ExecutableSize OPTIONAL,
1504+
OUT CONST CHAR8 **BundleVersion OPTIONAL
14991505
);
15001506

15011507
/**

Library/OcAppleKernelLib/CommonPatches.c

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ PatchAppleCpuPmCfgLock (
6565
return EFI_SUCCESS;
6666
}
6767

68-
ASSERT (Patcher != NULL);
68+
if (Patcher == NULL) {
69+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
70+
return EFI_NOT_FOUND;
71+
}
6972

7073
Count = 0;
7174
Walker = (UINT8 *)MachoGetMachHeader (&Patcher->MachContext);
@@ -648,6 +651,11 @@ PatchUsbXhciPortLimit1 (
648651
return EFI_SUCCESS;
649652
}
650653

654+
if (Patcher == NULL) {
655+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
656+
return EFI_NOT_FOUND;
657+
}
658+
651659
Status = PatcherApplyGenericPatch (Patcher, &mRemoveUsbLimitIoP1Patch);
652660
if (EFI_ERROR (Status)) {
653661
DEBUG ((DEBUG_INFO, "OCAK: Failed to apply port patch com.apple.iokit.IOUSBHostFamily - %r\n", Status));
@@ -667,13 +675,16 @@ PatchUsbXhciPortLimit2 (
667675
{
668676
EFI_STATUS Status;
669677

670-
ASSERT (Patcher != NULL);
671-
672678
if (!OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION_HIGH_SIERRA_MIN, 0)) {
673679
DEBUG ((DEBUG_INFO, "OCAK: Skipping modern port patch AppleUSBXHCI on %u\n", KernelVersion));
674680
return EFI_SUCCESS;
675681
}
676682

683+
if (Patcher == NULL) {
684+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
685+
return EFI_NOT_FOUND;
686+
}
687+
677688
//
678689
// TODO: Implement some locationID hack in IOUSBHostFamily.
679690
// The location ID is a 32 bit number which is unique among all USB devices in the system,
@@ -728,13 +739,16 @@ PatchUsbXhciPortLimit3 (
728739
{
729740
EFI_STATUS Status;
730741

731-
ASSERT (Patcher != NULL);
732-
733742
if (!OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION_EL_CAPITAN_MIN, KERNEL_VERSION_HIGH_SIERRA_MAX)) {
734743
DEBUG ((DEBUG_INFO, "OCAK: Skipping legacy port patch AppleUSBXHCIPCI on %u\n", KernelVersion));
735744
return EFI_SUCCESS;
736745
}
737746

747+
if (Patcher == NULL) {
748+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
749+
return EFI_NOT_FOUND;
750+
}
751+
738752
//
739753
// If we are here, we are on legacy 10.13 or below, try the oldest patch.
740754
//
@@ -819,7 +833,10 @@ PatchThirdPartyDriveSupport (
819833
{
820834
EFI_STATUS Status;
821835

822-
ASSERT (Patcher != NULL);
836+
if (Patcher == NULL) {
837+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
838+
return EFI_NOT_FOUND;
839+
}
823840

824841
Status = PatcherApplyGenericPatch (Patcher, &mIOAHCIBlockStoragePatchV1);
825842
if (EFI_ERROR (Status)) {
@@ -888,7 +905,10 @@ PatchForceInternalDiskIcons (
888905
{
889906
EFI_STATUS Status;
890907

891-
ASSERT (Patcher != NULL);
908+
if (Patcher == NULL) {
909+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
910+
return EFI_NOT_FOUND;
911+
}
892912

893913
Status = PatcherApplyGenericPatch (Patcher, &mIOAHCIPortPatch);
894914
if (EFI_ERROR (Status)) {
@@ -935,13 +955,16 @@ PatchAppleIoMapperSupport (
935955
{
936956
EFI_STATUS Status;
937957

938-
ASSERT (Patcher != NULL);
939-
940958
if (!OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION_MOUNTAIN_LION_MIN, 0)) {
941959
DEBUG ((DEBUG_INFO, "OCAK: Skipping AppleIoMapper patch on %u\n", KernelVersion));
942960
return EFI_SUCCESS;
943961
}
944962

963+
if (Patcher == NULL) {
964+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
965+
return EFI_NOT_FOUND;
966+
}
967+
945968
Status = PatcherApplyGenericPatch (Patcher, &mAppleIoMapperPatch);
946969
if (EFI_ERROR (Status)) {
947970
DEBUG ((DEBUG_INFO, "OCAK: Failed to apply patch com.apple.iokit.IOPCIFamily AppleIoMapper - %r\n", Status));
@@ -987,7 +1010,10 @@ PatchDummyPowerManagement (
9871010
return EFI_SUCCESS;
9881011
}
9891012

990-
ASSERT (Patcher != NULL);
1013+
if (Patcher == NULL) {
1014+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
1015+
return EFI_NOT_FOUND;
1016+
}
9911017

9921018
Status = PatcherApplyGenericPatch (Patcher, &mAppleDummyCpuPmPatch);
9931019
if (EFI_ERROR (Status)) {
@@ -1062,13 +1088,16 @@ PatchIncreasePciBarSize (
10621088
{
10631089
EFI_STATUS Status;
10641090

1065-
ASSERT (Patcher != NULL);
1066-
10671091
if (!OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION_YOSEMITE_MIN, 0)) {
10681092
DEBUG ((DEBUG_INFO, "OCAK: Skipping com.apple.iokit.IOPCIFamily IncreasePciBarSize on %u\n", KernelVersion));
10691093
return EFI_SUCCESS;
10701094
}
10711095

1096+
if (Patcher == NULL) {
1097+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
1098+
return EFI_NOT_FOUND;
1099+
}
1100+
10721101
Status = PatcherApplyGenericPatch (Patcher, &mIncreasePciBarSizePatch);
10731102
if (EFI_ERROR (Status)) {
10741103
DEBUG ((DEBUG_INFO, "OCAK: Failed to apply patch com.apple.iokit.IOPCIFamily IncreasePciBarSize - %r, trying legacy patch\n", Status));
@@ -1271,7 +1300,10 @@ PatchCustomSmbiosGuid (
12711300
{
12721301
EFI_STATUS Status;
12731302

1274-
ASSERT (Patcher != NULL);
1303+
if (Patcher == NULL) {
1304+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
1305+
return EFI_NOT_FOUND;
1306+
}
12751307

12761308
Status = PatcherApplyGenericPatch (Patcher, &mCustomSmbiosGuidPatch);
12771309
if (!EFI_ERROR (Status)) {
@@ -1705,7 +1737,10 @@ PatchAppleRtcChecksum (
17051737
{
17061738
EFI_STATUS Status;
17071739

1708-
ASSERT (Patcher != NULL);
1740+
if (Patcher == NULL) {
1741+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
1742+
return EFI_NOT_FOUND;
1743+
}
17091744

17101745
Status = PatcherApplyGenericPatch (Patcher, Patcher->Is32Bit ? &mAppleRtcChecksumPatch32 : &mAppleRtcChecksumPatch64);
17111746
if (EFI_ERROR (Status)) {
@@ -1866,13 +1901,16 @@ PatchBTFeatureFlags (
18661901
{
18671902
EFI_STATUS Status;
18681903

1869-
ASSERT (Patcher != NULL);
1870-
18711904
if (!OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION_MOUNTAIN_LION_MIN, 0)) {
18721905
DEBUG ((DEBUG_INFO, "OCAK: Skipping BTFeatureFlags on %u\n", KernelVersion));
18731906
return EFI_SUCCESS;
18741907
}
18751908

1909+
if (Patcher == NULL) {
1910+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
1911+
return EFI_NOT_FOUND;
1912+
}
1913+
18761914
Status = PatcherApplyGenericPatch (Patcher, &mBTFeatureFlagsPatchV1);
18771915
if (EFI_ERROR (Status)) {
18781916
DEBUG ((DEBUG_INFO, "OCAK: Failed to find BT FeatureFlags symbol v1 - %r, trying v2\n", Status));
@@ -2141,8 +2179,6 @@ PatchAquantiaEthernet (
21412179
{
21422180
EFI_STATUS Status;
21432181

2144-
ASSERT (Patcher != NULL);
2145-
21462182
//
21472183
// This patch is not required before macOS 10.15.4.
21482184
//
@@ -2151,6 +2187,11 @@ PatchAquantiaEthernet (
21512187
return EFI_SUCCESS;
21522188
}
21532189

2190+
if (Patcher == NULL) {
2191+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
2192+
return EFI_NOT_FOUND;
2193+
}
2194+
21542195
//
21552196
// Shikumo's patch can be applied to a wider range, not limited to AQC 107 series,
21562197
// thus preferred.
@@ -2188,13 +2229,16 @@ PatchForceSecureBootScheme (
21882229
UINT8 *HybridAp;
21892230
UINT32 Diff;
21902231

2191-
ASSERT (Patcher != NULL);
2192-
21932232
if (!OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION_BIG_SUR_MIN, 0)) {
21942233
DEBUG ((DEBUG_INFO, "OCAK: Skipping sb scheme on %u\n", KernelVersion));
21952234
return EFI_SUCCESS;
21962235
}
21972236

2237+
if (Patcher == NULL) {
2238+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
2239+
return EFI_NOT_FOUND;
2240+
}
2241+
21982242
//
21992243
// This code is for debugging APFS snapshot verification for Big Sur.
22002244
// macOS chooses verification scheme based on the hardware:
@@ -2308,13 +2352,16 @@ PatchSetApfsTrimTimeout (
23082352
{
23092353
EFI_STATUS Status;
23102354

2311-
ASSERT (Patcher != NULL);
2312-
23132355
if (!OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION_MOJAVE_MIN, 0)) {
23142356
DEBUG ((DEBUG_INFO, "OCAK: Skipping apfs timeout on %u\n", KernelVersion));
23152357
return EFI_SUCCESS;
23162358
}
23172359

2360+
if (Patcher == NULL) {
2361+
DEBUG ((DEBUG_INFO, "OCAK: Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
2362+
return EFI_NOT_FOUND;
2363+
}
2364+
23182365
//
23192366
// Disable trim using another patch when timeout is 0.
23202367
//

Library/OcAppleKernelLib/MkextContext.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,8 @@ MkextInjectKext (
11961196
IN CONST CHAR8 *InfoPlist,
11971197
IN UINT32 InfoPlistSize,
11981198
IN UINT8 *Executable OPTIONAL,
1199-
IN UINT32 ExecutableSize OPTIONAL
1199+
IN UINT32 ExecutableSize OPTIONAL,
1200+
OUT CONST CHAR8 **BundleVersion OPTIONAL
12001201
)
12011202
{
12021203
UINT32 MkextNewSize;
@@ -1210,6 +1211,7 @@ MkextInjectKext (
12101211
UINT32 PlistExportedSize;
12111212
XML_DOCUMENT *PlistXml;
12121213
XML_NODE *PlistRoot;
1214+
XML_NODE *KextPlistValue;
12131215
BOOLEAN PlistFailed;
12141216
UINT32 PlistBundleIndex;
12151217
UINT32 PlistBundleCount;
@@ -1228,6 +1230,13 @@ MkextInjectKext (
12281230
ASSERT (InfoPlist != NULL);
12291231
ASSERT (InfoPlistSize > 0);
12301232

1233+
//
1234+
// Assume no bundle version from the beginning.
1235+
//
1236+
if (BundleVersion != NULL) {
1237+
*BundleVersion = NULL;
1238+
}
1239+
12311240
BinOffset = 0;
12321241

12331242
//
@@ -1264,8 +1273,30 @@ MkextInjectKext (
12641273
// code in debug mode to diagnose it.
12651274
//
12661275
DEBUG_CODE_BEGIN ();
1267-
if (Executable == NULL) {
12681276
FieldCount = PlistDictChildren (PlistRoot);
1277+
1278+
if (BundleVersion != NULL) {
1279+
for (FieldIndex = 0; FieldIndex < FieldCount; ++FieldIndex) {
1280+
TmpKeyValue = PlistKeyValue (PlistDictChild (PlistRoot, FieldIndex, &KextPlistValue));
1281+
if (TmpKeyValue == NULL) {
1282+
continue;
1283+
}
1284+
1285+
//
1286+
// Match CFBundleVersion.
1287+
//
1288+
if (AsciiStrCmp (TmpKeyValue, INFO_BUNDLE_VERSION_KEY) == 0) {
1289+
if (PlistNodeCast (KextPlistValue, PLIST_NODE_TYPE_STRING) == NULL) {
1290+
break;
1291+
}
1292+
1293+
*BundleVersion = XmlNodeContent (KextPlistValue);
1294+
break;
1295+
}
1296+
}
1297+
}
1298+
1299+
if (Executable == NULL) {
12691300
for (FieldIndex = 0; FieldIndex < FieldCount; ++FieldIndex) {
12701301
TmpKeyValue = PlistKeyValue (PlistDictChild (PlistRoot, FieldIndex, NULL));
12711302
if (TmpKeyValue == NULL) {

0 commit comments

Comments
 (0)