Skip to content

Commit

Permalink
Add guards around memcmp and memset to fix ubsan runtime errors. (#74282
Browse files Browse the repository at this point in the history
)

Co-authored-by: Jan Kotas <[email protected]>
  • Loading branch information
RobertHenry6bev and jkotas authored Aug 20, 2022
1 parent 1d94433 commit 5958eeb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/coreclr/inc/sbuffer.inl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ inline void SBuffer::Set(const BYTE *buffer, COUNT_T size)
// From the code for Resize, this is clearly impossible.
PREFIX_ASSUME( (this->m_buffer != NULL) || (size == 0) );

MoveMemory(m_buffer, buffer, size);
if (size != 0)
MoveMemory(m_buffer, buffer, size);

RETURN;
}
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/vm/baseassemblyspec.inl
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,11 @@ inline BOOL BaseAssemblySpec::CompareEx(BaseAssemblySpec *pSpec, DWORD dwCompare
|| strcmp(m_pAssemblyName, pSpec->m_pAssemblyName)))
return FALSE;

if (m_cbPublicKeyOrToken != pSpec->m_cbPublicKeyOrToken
|| memcmp(m_pbPublicKeyOrToken, pSpec->m_pbPublicKeyOrToken, m_cbPublicKeyOrToken))
if (m_cbPublicKeyOrToken != pSpec->m_cbPublicKeyOrToken)
return FALSE;

if (m_cbPublicKeyOrToken != 0 && memcmp(m_pbPublicKeyOrToken, pSpec->m_pbPublicKeyOrToken, m_cbPublicKeyOrToken) != 0)
return FALSE;

if (m_dwFlags != pSpec->m_dwFlags)
return FALSE;
Expand Down

0 comments on commit 5958eeb

Please sign in to comment.