Skip to content

Commit

Permalink
Fix write behind allocated memory in thread name setting (#34424) (#3…
Browse files Browse the repository at this point in the history
…4437)

The code in CorUnix::InternalSetThreadDescription is writing behind
the end of the allocated memory in case the name is shorter than 16
characters. That is causing memory heap corruption.

Co-authored-by: Jan Vorlicek <janvorli@microsoft.com>
  • Loading branch information
mmitche and janvorli authored Apr 2, 2020
1 parent 73da9bb commit 2b487f3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/coreclr/src/pal/src/thread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,10 @@ CorUnix::InternalSetThreadDescription(

// Null terminate early.
// pthread_setname_np only accepts up to 16 chars.
nameBuf[15] = '\0';
if (nameSize > 15)
{
nameBuf[15] = '\0';
}

error = pthread_setname_np(pTargetThread->GetPThreadSelf(), nameBuf);

Expand Down

0 comments on commit 2b487f3

Please sign in to comment.