diff options
author | Phil Christensen <philc@microsoft.com> | 2016-12-01 03:53:23 -0800 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2016-12-01 12:53:23 +0100 |
commit | 20275aa647c5733bc5b1929cba3fd1094c67fb1d (patch) | |
tree | 83175127d46a1eaf0071747a92876f3b3e43a6fa /src/utilcode | |
parent | 3f4680c80dc510a96efa322054145a807480bab7 (diff) | |
download | coreclr-20275aa647c5733bc5b1929cba3fd1094c67fb1d.tar.gz coreclr-20275aa647c5733bc5b1929cba3fd1094c67fb1d.tar.bz2 coreclr-20275aa647c5733bc5b1929cba3fd1094c67fb1d.zip |
fix permissive C++ code (MSVC /permissive-) (#8337)
* fix permissive C++ code (MSVC /permissive-)
These were found by the C++ compiler group when doing "Real world code"
build tests using /permissive-. We are sharing these with you to help you clean up
your code before the new version of the compiler comes out. For more information on /permissive-
see https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/.
----------------------------
Under /permissive-, skipping the initialization of a variable is not allowed.
As an extension the compiler allowed this when there was no destructor for the type.
void func(bool b)
{
if(b) goto END;
int value = 0; //error C2362: initialization of 'value' is skipped by 'goto END'
int array[10]; //Okay, not initialized.
//... value used here
END:
return;
}
Fix 1) Limit the scope of value:
{
int value = 0;
//... value used here
}
END:
Fix 2) Initialize/declare value before the 'goto'
int value = 0;
if(b) goto END;
//... value used here
END:
Fix 3) Don't initialize value in the variable declaration.
int value;
value = 0
//... value used here
END:
-------------------
Alternative token representations.
The following are reserved as alternative representations for operators:
and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq
//Can't use reserved names for variables:
static int and = 0; // Change name (possibly to 'and_')
void func()
{
_asm {
xor edx,edx // xor is reserved, change to uppercase XOR
or eax,eax // or is reserved, change to uppercase OR
}
}
* Apply formatting patch.
* fixes from code review.
I addressed @janvorli requests from the pull request code review.
Diffstat (limited to 'src/utilcode')
-rw-r--r-- | src/utilcode/regutil.cpp | 3 | ||||
-rw-r--r-- | src/utilcode/securitywrapper.cpp | 35 |
2 files changed, 20 insertions, 18 deletions
diff --git a/src/utilcode/regutil.cpp b/src/utilcode/regutil.cpp index fbc55708c7..d611ef965f 100644 --- a/src/utilcode/regutil.cpp +++ b/src/utilcode/regutil.cpp @@ -1439,8 +1439,7 @@ void REGUTIL::InitOptionalConfigCache() s_fUseRegCache = TRUE; // Now create a cache of environment variables - WCHAR * wszStrings = WszGetEnvironmentStrings(); - if (wszStrings) + if (WCHAR * wszStrings = WszGetEnvironmentStrings()) { // GetEnvironmentStrings returns pointer to a null terminated block containing // null terminated strings diff --git a/src/utilcode/securitywrapper.cpp b/src/utilcode/securitywrapper.cpp index f949b26df1..0f146ab55e 100644 --- a/src/utilcode/securitywrapper.cpp +++ b/src/utilcode/securitywrapper.cpp @@ -412,6 +412,7 @@ HRESULT SidBuffer::InitFromProcessAppContainerSidNoThrow(DWORD pid) { HRESULT hr = S_OK; HANDLE hToken = NULL; + BOOL fIsLowBox = FALSE; HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); if (hProcess == NULL) @@ -438,7 +439,6 @@ HRESULT SidBuffer::InitFromProcessAppContainerSidNoThrow(DWORD pid) } TOKEN_APPCONTAINER_INFORMATION, *PTOKEN_APPCONTAINER_INFORMATION; DWORD size; - BOOL fIsLowBox = FALSE; if (!GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)TokenIsAppContainer, &fIsLowBox, sizeof(fIsLowBox), &size)) { DWORD gle = GetLastError(); @@ -466,24 +466,26 @@ HRESULT SidBuffer::InitFromProcessAppContainerSidNoThrow(DWORD pid) goto exit; } - PTOKEN_APPCONTAINER_INFORMATION pTokPack = (PTOKEN_APPCONTAINER_INFORMATION)&PackSid; - PSID pLowBoxPackage = pTokPack->TokenPackage; - DWORD dwSidLen = GetLengthSid(pLowBoxPackage); - m_pBuffer = new (nothrow) BYTE[dwSidLen]; - if (m_pBuffer == NULL) - { - hr = E_OUTOFMEMORY; - goto exit; - } - else { - if (!CopySid(dwSidLen, m_pBuffer, pLowBoxPackage)) + PTOKEN_APPCONTAINER_INFORMATION pTokPack = (PTOKEN_APPCONTAINER_INFORMATION)&PackSid; + PSID pLowBoxPackage = pTokPack->TokenPackage; + DWORD dwSidLen = GetLengthSid(pLowBoxPackage); + m_pBuffer = new (nothrow) BYTE[dwSidLen]; + if (m_pBuffer == NULL) { - hr = HRESULT_FROM_GetLastError(); - delete m_pBuffer; - m_pBuffer = NULL; + hr = E_OUTOFMEMORY; goto exit; } + else + { + if (!CopySid(dwSidLen, m_pBuffer, pLowBoxPackage)) + { + hr = HRESULT_FROM_GetLastError(); + delete m_pBuffer; + m_pBuffer = NULL; + goto exit; + } + } } exit: @@ -790,6 +792,7 @@ bool IsHandleSpoofed(HANDLE handle, DWORD pid) SidBuffer sbPidOther; SidBuffer sbPidThis; + DWORD pidThis; // Is the object owner the "other" pid? sbPidOther.InitFromProcess(pid); @@ -805,7 +808,7 @@ bool IsHandleSpoofed(HANDLE handle, DWORD pid) // This can happen if the other process impersonates us. The most common case would // be if we're an admin and the other process (say some service) is impersonating Admin // when it spins up the CLR. - DWORD pidThis = GetCurrentProcessId(); + pidThis = GetCurrentProcessId(); if (pidThis != pid) { sbPidThis.InitFromProcess(pidThis); |