Fix OpenProcessToken pseudo-handle regression

This commit is contained in:
2025-10-05 18:16:15 -06:00
parent 0d76e541c1
commit ff04eb9f41
6 changed files with 31 additions and 25 deletions

View File

@@ -23,7 +23,7 @@ BOOL WIN_FUNC DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle,
}
auto validateProcessHandle = [&](HANDLE handle) -> bool {
if (reinterpret_cast<uintptr_t>(handle) == kPseudoCurrentProcessHandleValue) {
if (isPseudoCurrentProcessHandle(handle)) {
return true;
}
auto proc = wibo::handles().getAs<ProcessObject>(handle);
@@ -37,15 +37,14 @@ BOOL WIN_FUNC DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle,
return FALSE;
}
uintptr_t sourceHandleRaw = reinterpret_cast<uintptr_t>(hSourceHandle);
if (sourceHandleRaw == kPseudoCurrentProcessHandleValue) {
if (isPseudoCurrentProcessHandle(hSourceHandle)) {
auto po = make_pin<ProcessObject>(getpid(), -1);
auto handle = wibo::handles().alloc(std::move(po), 0, 0);
DEBUG_LOG("DuplicateHandle: created process handle for current process -> %p\n", handle);
*lpTargetHandle = handle;
wibo::lastError = ERROR_SUCCESS;
return TRUE;
} else if (sourceHandleRaw == kPseudoCurrentThreadHandleValue) {
} else if (isPseudoCurrentThreadHandle(hSourceHandle)) {
auto th = make_pin<ThreadObject>(pthread_self());
auto handle = wibo::handles().alloc(std::move(th), 0, 0);
DEBUG_LOG("DuplicateHandle: created thread handle for current thread -> %p\n", handle);