OcAppleKernelLib: Fix potential NULL dereferences
Fixes Coverity 302191 and 302192
@@ -796,6 +796,8 @@ InternalCachedPrelinkedKernel (
PRELINK_STATE_SECTION_KEXTS
);
+ if (Prelinked->PrelinkedStateSectionKernel != NULL
+ && Prelinked->PrelinkedStateSectionKexts != NULL) {
KernelSize = Prelinked->Is32Bit ?
Prelinked->PrelinkedStateSectionKernel->Section32.Size :
Prelinked->PrelinkedStateSectionKernel->Section64.Size;
@@ -809,10 +811,7 @@ InternalCachedPrelinkedKernel (
Prelinked->PrelinkedStateSectionKexts->Section32.Offset :
Prelinked->PrelinkedStateSectionKexts->Section64.Offset;
- if (Prelinked->PrelinkedStateSectionKernel != NULL
- && Prelinked->PrelinkedStateSectionKexts != NULL
- && KernelSize > 0
- && KextsSize > 0) {
+ if (KernelSize > 0 && KextsSize > 0) {
Prelinked->PrelinkedStateKernelSize = (UINT32) KernelSize;
Prelinked->PrelinkedStateKextsSize = (UINT32) KextsSize;
Prelinked->PrelinkedStateKernel = AllocateCopyPool (
@@ -823,8 +822,6 @@ InternalCachedPrelinkedKernel (
Prelinked->PrelinkedStateKextsSize,
&Prelinked->Prelinked[KextsOffset]
);
- }
-
if (Prelinked->PrelinkedStateKernel != NULL
&& Prelinked->PrelinkedStateKexts != NULL) {
Prelinked->PrelinkedStateKextsAddress = Prelinked->Is32Bit ?
@@ -851,6 +848,8 @@ InternalCachedPrelinkedKernel (
}
}
}
+ }
+ }
InsertTailList (&Prelinked->PrelinkedKexts, &NewKext->Link);
