diff --git a/Changelog.md b/Changelog.md index bca2831248..35c1566c55 100644 --- a/Changelog.md +++ b/Changelog.md @@ -23,6 +23,7 @@ AppleALC Changelog - Added ALC887 layout-id 33 for GA-Q87TN by klblk - Added ALC256 (3246) codec support layout-id 13 by InsanelyDeepak - Added ALC255 layout-id 13 and 17 by InsanelyDeepak +- Fixed an extremely rare crash on 10.12 #### v1.0.16 - Fixed a rare lock acquisition issue on 10.12 diff --git a/Common/kern_patcher.cpp b/Common/kern_patcher.cpp index f495fe43d8..e9a4a508dd 100644 --- a/Common/kern_patcher.cpp +++ b/Common/kern_patcher.cpp @@ -214,27 +214,30 @@ void KernelPatcher::applyLookupPatch(const LookupPatch *patch) { curr = off; off += size - patch->size; size_t changes {0}; + + if (kinfo->setKernelWriting(true) != KERN_SUCCESS) { + SYSLOG("patcher @ lookup patching failed to write to kernel"); + code = Error::MemoryProtection; + return; + } + for (size_t i = 0; curr < off && (i < patch->count || patch->count == 0); i++) { while (curr < off && memcmp(curr, patch->find, patch->size)) curr++; if (curr != off) { - if (kinfo->setKernelWriting(true) != KERN_SUCCESS) { - SYSLOG("patcher @ lookup patching failed to write to kernel"); - code = Error::MemoryProtection; - return; - } for (size_t j = 0; j < patch->size; j++) { curr[j] = patch->replace[j]; } - if (kinfo->setKernelWriting(false) != KERN_SUCCESS) { - SYSLOG("patcher @ lookup patching failed to disable kernel writing"); - code = Error::MemoryProtection; - return; - } changes++; } } + + if (kinfo->setKernelWriting(false) != KERN_SUCCESS) { + SYSLOG("patcher @ lookup patching failed to disable kernel writing"); + code = Error::MemoryProtection; + return; + } if (changes != patch->count) { SYSLOG("patcher @ lookup patching applied only %zu patches out of %zu", changes, patch->count); @@ -424,4 +427,4 @@ void KernelPatcher::onKextSummariesUpdated() { } } } -#endif /* KEXTPATCH_SUPPORT */ \ No newline at end of file +#endif /* KEXTPATCH_SUPPORT */