Skip to content

Commit

Permalink
Fix write behind allocated memory in thread name setting (#34424)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
janvorli authored Apr 2, 2020
1 parent b5d044d commit c03c529
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 c03c529

Please sign in to comment.