[VCRUNTIME] Fix a bug in x64 __security_init_cookie

This commit is contained in:
Timo Kreuzer 2025-04-06 18:06:16 +03:00
parent 182f353b2f
commit 52719b52ae

View file

@ -70,16 +70,17 @@ void __security_init_cookie(void)
randomValue += GetCurrentProcessId(); randomValue += GetCurrentProcessId();
randomValue = _rotlptr(randomValue, GetCurrentProcessId() >> 2); randomValue = _rotlptr(randomValue, GetCurrentProcessId() >> 2);
if (randomValue == DEFAULT_SECURITY_COOKIE)
{
randomValue++;
}
#ifdef _WIN64 #ifdef _WIN64
/* Zero out highest 16 bits */ /* Zero out highest 16 bits */
randomValue &= 0x0000FFFFFFFFFFFFull; randomValue &= 0x0000FFFFFFFFFFFFull;
#endif #endif
/* Avoid the default security cookie */
if (randomValue == DEFAULT_SECURITY_COOKIE)
{
randomValue++;
}
__security_cookie = randomValue; __security_cookie = randomValue;
__security_cookie_complement = ~randomValue; __security_cookie_complement = ~randomValue;
} }