summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoundinya Veluri <kouvel@microsoft.com>2017-05-09 13:56:40 -0700
committerGitHub <noreply@github.com>2017-05-09 13:56:40 -0700
commitc8a37801f8483d05766e0bf053ffa41aaa155f2c (patch)
tree8e01a17aa262b0779668b845069bd57d2d50d67b
parent39a841c33a6ae70cc887ee9fa7cfdeb834c6ca59 (diff)
downloadcoreclr-c8a37801f8483d05766e0bf053ffa41aaa155f2c.tar.gz
coreclr-c8a37801f8483d05766e0bf053ffa41aaa155f2c.tar.bz2
coreclr-c8a37801f8483d05766e0bf053ffa41aaa155f2c.zip
Fix static analysis issues (#11466)
Fix static analysis issues
-rw-r--r--src/debug/shared/amd64/primitives.cpp2
-rw-r--r--src/dlls/mscorpe/iceefilegen.cpp4
-rw-r--r--src/ilasm/prebuilt/asmparse.cpp11
-rw-r--r--src/inc/winrt/paraminstanceapi.h7
-rw-r--r--src/md/ceefilegen/cceegen.cpp30
-rw-r--r--src/md/enc/mdinternalrw.cpp2
-rw-r--r--src/vm/ceeload.cpp8
-rw-r--r--src/vm/corhost.cpp2
-rw-r--r--src/vm/dwreport.cpp42
-rw-r--r--src/vm/jitinterface.cpp2
-rw-r--r--src/vm/methodtable.h2
-rw-r--r--src/zap/zapheaders.cpp2
-rw-r--r--src/zap/zapimage.cpp6
13 files changed, 77 insertions, 43 deletions
diff --git a/src/debug/shared/amd64/primitives.cpp b/src/debug/shared/amd64/primitives.cpp
index fb5d95b0d6..6fead570cf 100644
--- a/src/debug/shared/amd64/primitives.cpp
+++ b/src/debug/shared/amd64/primitives.cpp
@@ -63,7 +63,7 @@ void CORDbgCopyThreadContext(DT_CONTEXT* pDst, const DT_CONTEXT* pSrc)
if ((dstFlags & srcFlags & CONTEXT_FLOATING_POINT) == CONTEXT_FLOATING_POINT)
{
// Xmm0-Xmm15
- CopyContextChunk(&(pDst->Xmm0), &(pSrc->Xmm0), &(pDst->Xmm15) + sizeof(M128A),
+ CopyContextChunk(&(pDst->Xmm0), &(pSrc->Xmm0), &(pDst->Xmm15) + 1,
CONTEXT_FLOATING_POINT);
// MxCsr
diff --git a/src/dlls/mscorpe/iceefilegen.cpp b/src/dlls/mscorpe/iceefilegen.cpp
index f4323b9e8c..c48ae7e094 100644
--- a/src/dlls/mscorpe/iceefilegen.cpp
+++ b/src/dlls/mscorpe/iceefilegen.cpp
@@ -151,7 +151,9 @@ HRESULT ICeeFileGen::CreateCeeFileFromICeeGen(ICeeGen *pICeeGen, HCEEFILE *ceeFi
return E_POINTER;
CCeeGen *genFrom = reinterpret_cast<CCeeGen*>(pICeeGen);
CeeFileGenWriter *gen = NULL;
- if (FAILED(CeeFileGenWriter::CreateNewInstance(genFrom, gen, createFlags))) return FALSE;
+ HRESULT hr = CeeFileGenWriter::CreateNewInstance(genFrom, gen, createFlags);
+ if (FAILED(hr))
+ return hr;
TESTANDRETURN(gen != NULL, E_OUTOFMEMORY);
*ceeFile = gen;
return S_OK;
diff --git a/src/ilasm/prebuilt/asmparse.cpp b/src/ilasm/prebuilt/asmparse.cpp
index b3571c72b7..389546edb2 100644
--- a/src/ilasm/prebuilt/asmparse.cpp
+++ b/src/ilasm/prebuilt/asmparse.cpp
@@ -1834,9 +1834,16 @@ YYSTATIC char *yyscpy(register char*t, register char*f)
YYSTATIC short yyn;
YYSTATIC short yystate = 0;
- YYSTATIC short *yyps= &yys[-1];
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable: 6200) // Index '-1' is out of valid index range...for non-stack buffer...
+#endif
+ YYSTATIC short *yyps= &yys[-1];
YYSTATIC YYSTYPE *yypv= &yyv[-1];
- YYSTATIC short yyj;
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
+ YYSTATIC short yyj;
YYSTATIC short yym;
#endif
diff --git a/src/inc/winrt/paraminstanceapi.h b/src/inc/winrt/paraminstanceapi.h
index 062c7f3d08..81ee4c51c9 100644
--- a/src/inc/winrt/paraminstanceapi.h
+++ b/src/inc/winrt/paraminstanceapi.h
@@ -1642,7 +1642,14 @@ namespace Ro { namespace detail {
DWORD dwcb;
DWORD dwcbResult;
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable: 33098) // "Banned hash algorithm is used" - SHA-1 is required for compatibility
+#endif // _PREFAST_
CHKNT(BCryptOpenAlgorithmProvider(&_hAlg, BCRYPT_SHA1_ALGORITHM, MS_PRIMITIVE_PROVIDER, 0));
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif // _PREFAST_
CHKNT(BCryptGetProperty(_hAlg, BCRYPT_OBJECT_LENGTH, reinterpret_cast<PBYTE>(&dwcb), sizeof(dwcb), &dwcbResult, 0));
diff --git a/src/md/ceefilegen/cceegen.cpp b/src/md/ceefilegen/cceegen.cpp
index 0cf0780d15..bd69c8daed 100644
--- a/src/md/ceefilegen/cceegen.cpp
+++ b/src/md/ceefilegen/cceegen.cpp
@@ -38,22 +38,30 @@ HRESULT STDMETHODCALLTYPE CreateICeeGen(REFIID riid, void **pCeeGen)
HRESULT CCeeGen::CreateNewInstance(CCeeGen* & pGen) // static, public
{
- pGen = new CCeeGen();
- _ASSERTE(pGen != NULL);
- TESTANDRETURNMEMORY(pGen);
+ NewHolder<CCeeGen> pGenHolder(new CCeeGen());
+ _ASSERTE(pGenHolder != NULL);
+ TESTANDRETURNMEMORY(pGenHolder);
- pGen->m_peSectionMan = new PESectionMan;
- _ASSERTE(pGen->m_peSectionMan != NULL);
- TESTANDRETURNMEMORY(pGen->m_peSectionMan);
+ pGenHolder->m_peSectionMan = new PESectionMan;
+ _ASSERTE(pGenHolder->m_peSectionMan != NULL);
+ TESTANDRETURNMEMORY(pGenHolder->m_peSectionMan);
- HRESULT hr = pGen->m_peSectionMan->Init();
- TESTANDRETURNHR(hr);
+ HRESULT hr = pGenHolder->m_peSectionMan->Init();
+ if (FAILED(hr))
+ {
+ pGenHolder->Cleanup();
+ return hr;
+ }
- hr = pGen->Init();
- TESTANDRETURNHR(hr);
+ hr = pGenHolder->Init();
+ if (FAILED(hr))
+ {
+ // Init() calls Cleanup() on failure
+ return hr;
+ }
+ pGen = pGenHolder.Extract();
return hr;
-
}
STDMETHODIMP CCeeGen::QueryInterface(REFIID riid, void** ppv)
diff --git a/src/md/enc/mdinternalrw.cpp b/src/md/enc/mdinternalrw.cpp
index 02fb407358..75c793967e 100644
--- a/src/md/enc/mdinternalrw.cpp
+++ b/src/md/enc/mdinternalrw.cpp
@@ -2393,7 +2393,7 @@ HRESULT MDInternalRW::GetItemGuid( // return hresult
// Get the GUID, if any.
hr = GetCustomAttributeByName(tkObj, INTEROP_GUID_TYPE, (const void**)&pBlob, &cbBlob);
- if (hr != S_FALSE)
+ if (SUCCEEDED(hr) && hr != S_FALSE)
{
// Should be in format. Total length == 41
// <0x0001><0x24>01234567-0123-0123-0123-001122334455<0x0000>
diff --git a/src/vm/ceeload.cpp b/src/vm/ceeload.cpp
index 5de7114eb1..41ea693d03 100644
--- a/src/vm/ceeload.cpp
+++ b/src/vm/ceeload.cpp
@@ -12770,6 +12770,11 @@ void Module::LogTokenAccess(mdToken token, SectionFormat format, ULONG flagnum)
if (!m_nativeImageProfiling)
return;
+ if (flagnum >= CORBBTPROF_TOKEN_MAX_NUM_FLAGS)
+ {
+ return;
+ }
+
mdToken rid = RidFromToken(token);
CorTokenType tkType = (CorTokenType) TypeFromToken(token);
SectionFormat tkKind = (SectionFormat) (tkType >> 24);
@@ -12798,8 +12803,9 @@ void Module::LogTokenAccess(mdToken token, SectionFormat format, ULONG flagnum)
else if (tkKind == (SectionFormat) (ibcMethodSpec >> 24))
tkKind = IbcMethodSpecSection;
+ _ASSERTE(tkKind >= 0);
_ASSERTE(tkKind < SectionFormatCount);
- if (tkKind >= SectionFormatCount)
+ if (tkKind < 0 || tkKind >= SectionFormatCount)
{
return;
}
diff --git a/src/vm/corhost.cpp b/src/vm/corhost.cpp
index fd27a7a4e7..3f53de2acb 100644
--- a/src/vm/corhost.cpp
+++ b/src/vm/corhost.cpp
@@ -2570,7 +2570,7 @@ HRESULT CCLRErrorReportingManager::BucketParamsCache::SetAt(BucketParameterIndex
{
LIMITED_METHOD_CONTRACT;
- if (index >= InvalidBucketParamIndex)
+ if (index < 0 || index >= InvalidBucketParamIndex)
{
_ASSERTE(!"bad bucket parameter index");
return E_INVALIDARG;
diff --git a/src/vm/dwreport.cpp b/src/vm/dwreport.cpp
index b95c59ff8d..57d67e7c22 100644
--- a/src/vm/dwreport.cpp
+++ b/src/vm/dwreport.cpp
@@ -1526,30 +1526,28 @@ BOOL RunWatson(
return false;
}
+ {
+ BOOL ret = WszCreateProcess(watsonAppName,
+ watsonCommandLine,
+ NULL,
+ NULL,
+ TRUE,
+ NULL,
+ NULL,
+ NULL,
+ &startupInfo,
+ &processInformation);
+
+ if (FALSE == ret)
{
- BOOL ret = WszCreateProcess(watsonAppName,
- watsonCommandLine,
- NULL,
- NULL,
- TRUE,
- NULL,
- NULL,
- NULL,
- &startupInfo,
- &processInformation);
-
- if (FALSE == ret)
- {
- //
- // Watson failed to start up.
- //
- // This can happen if e.g. Watson wasn't installed on the machine.
- //
- return E_FAIL;
-
- }
-
+ //
+ // Watson failed to start up.
+ //
+ // This can happen if e.g. Watson wasn't installed on the machine.
+ //
+ return FALSE;
}
+ }
diff --git a/src/vm/jitinterface.cpp b/src/vm/jitinterface.cpp
index b67ab0c397..6de4163c69 100644
--- a/src/vm/jitinterface.cpp
+++ b/src/vm/jitinterface.cpp
@@ -360,7 +360,7 @@ CorInfoType CEEInfo::asCorInfoType(CorElementType eeType,
_ASSERTE((CorInfoType) map[ELEMENT_TYPE_PTR] == CORINFO_TYPE_PTR);
_ASSERTE((CorInfoType) map[ELEMENT_TYPE_TYPEDBYREF] == CORINFO_TYPE_REFANY);
- CorInfoType res = ((unsigned)eeType < ELEMENT_TYPE_MAX) ? ((CorInfoType) map[eeType]) : CORINFO_TYPE_UNDEF;
+ CorInfoType res = ((unsigned)eeType < ELEMENT_TYPE_MAX) ? ((CorInfoType) map[(unsigned)eeType]) : CORINFO_TYPE_UNDEF;
if (clsRet)
*clsRet = CORINFO_CLASS_HANDLE(typeHndUpdated.AsPtr());
diff --git a/src/vm/methodtable.h b/src/vm/methodtable.h
index 1e557c4253..2ce9f2a883 100644
--- a/src/vm/methodtable.h
+++ b/src/vm/methodtable.h
@@ -663,7 +663,7 @@ SystemVClassificationType CorInfoType2UnixAmd64Classification(CorElementType eeT
_ASSERTE((SystemVClassificationType)toSystemVAmd64ClassificationTypeMap[ELEMENT_TYPE_TYPEDBYREF] == SystemVClassificationTypeTypedReference);
_ASSERTE((SystemVClassificationType)toSystemVAmd64ClassificationTypeMap[ELEMENT_TYPE_BYREF] == SystemVClassificationTypeIntegerByRef);
- return (((unsigned)eeType) < ELEMENT_TYPE_MAX) ? (toSystemVAmd64ClassificationTypeMap[eeType]) : SystemVClassificationTypeUnknown;
+ return (((unsigned)eeType) < ELEMENT_TYPE_MAX) ? (toSystemVAmd64ClassificationTypeMap[(unsigned)eeType]) : SystemVClassificationTypeUnknown;
};
#define SYSTEMV_EIGHT_BYTE_SIZE_IN_BYTES 8 // Size of an eightbyte in bytes.
diff --git a/src/zap/zapheaders.cpp b/src/zap/zapheaders.cpp
index acec36bf2a..8960798981 100644
--- a/src/zap/zapheaders.cpp
+++ b/src/zap/zapheaders.cpp
@@ -325,7 +325,7 @@ ZapPEExports::ZapPEExports(LPCWSTR dllPath)
DWORD ZapPEExports::GetSize()
{
- return DWORD(sizeof(IMAGE_EXPORT_DIRECTORY) + wcslen(m_dllFileName) + 1);
+ return DWORD(sizeof(IMAGE_EXPORT_DIRECTORY) + wcslen(m_dllFileName) * sizeof(BYTE) + 1);
}
void ZapPEExports::Save(ZapWriter * pZapWriter)
diff --git a/src/zap/zapimage.cpp b/src/zap/zapimage.cpp
index 27b46520be..61cf099898 100644
--- a/src/zap/zapimage.cpp
+++ b/src/zap/zapimage.cpp
@@ -2620,6 +2620,12 @@ HRESULT ZapImage::parseProfileData()
READ(entry,CORBBTPROF_SECTION_TABLE_ENTRY);
SectionFormat format = sectionHeader->Entries[i].FormatID;
+ _ASSERTE(format >= 0);
+ if (format < 0)
+ {
+ continue;
+ }
+
if (convertFromV1)
{
if (format < LastTokenFlagSection)