From a58b713a5e32a8ca23f4e514aad65c8b0c1e8c30 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sun, 10 Nov 2024 16:01:21 +0200 Subject: [PATCH] [UCRT] Properly implement __crt_fast_encode/decode_pointer --- sdk/lib/ucrt/inc/internal_shared.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sdk/lib/ucrt/inc/internal_shared.h b/sdk/lib/ucrt/inc/internal_shared.h index 08c1cb79463..7ad4b4bafe3 100644 --- a/sdk/lib/ucrt/inc/internal_shared.h +++ b/sdk/lib/ucrt/inc/internal_shared.h @@ -166,18 +166,20 @@ extern char __ImageBase; template __forceinline -T __crt_fast_encode_pointer(T Ptr) +T __crt_fast_encode_pointer(T ptr) { - // FIXME: use cookie - return Ptr; + union { T Ptr; uintptr_t Uint; } u = { ptr }; + u.Uint ^= __security_cookie; + return u.Ptr; } template __forceinline -T __crt_fast_decode_pointer(T Ptr) +T __crt_fast_decode_pointer(T ptr) { - // FIXME: use cookie - return Ptr; + union { T Ptr; uintptr_t Uint; } u = { ptr }; + u.Uint ^= __security_cookie; + return u.Ptr; } template