Uninitialized pointer bug in _MCFCRT_TlsGet()
Closed this issue · 2 comments
lhmouse commented
Upon return of _MCFCRT_TlsGet()
on [1] or [2] the content of *ppStorage
is left uninitialized and attempt to use that value results in undefined behavior:
TlsKey *const pKey = (TlsKey *)hTlsKey;
if(!pKey){
SetLastError(ERROR_INVALID_PARAMETER);
return false;
}
TlsThread *const pThread = GetTlsForCurrentThread();
if(!pThread){
return true; // [1]
}
TlsObject *const pObject = GetTlsObject(pThread, pKey);
if(!pObject){
return true; // [2]
}
lhmouse commented
This is a false error, as there used to be *ppStorage = nullptr;
on the first line.
But since this was obscure, I replaced it with
#ifndef NDEBUG
*ppStorage = (void *)0xDEADBEEF;
#endif
And upon a return value of true
we shall set the value properly.
lhmouse commented
Re-marked as enhancement.