Skip to content

Commit 2b487f3

Browse files
mmitchejanvorli
andauthored
Fix write behind allocated memory in thread name setting (#34424) (#34437)
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>
1 parent 73da9bb commit 2b487f3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/coreclr/src/pal/src/thread/thread.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,10 @@ CorUnix::InternalSetThreadDescription(
16661666

16671667
// Null terminate early.
16681668
// pthread_setname_np only accepts up to 16 chars.
1669-
nameBuf[15] = '\0';
1669+
if (nameSize > 15)
1670+
{
1671+
nameBuf[15] = '\0';
1672+
}
16701673

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

0 commit comments

Comments
 (0)