Skip to content

Commit bc12cc3

Browse files
authored
[RuntimeAsync] Use truncating sprintf to make resumption stub names (#120698)
* Use truncating sprintf to make resumption stub names * make sure the resumption stub's name fits instead of truncating.
1 parent 53110aa commit bc12cc3

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/coreclr/vm/jitinterface.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14818,19 +14818,20 @@ CORINFO_METHOD_HANDLE CEEJitInfo::getAsyncResumptionStub()
1481814818
}
1481914819
#endif // FEATURE_TIERED_COMPILATION
1482014820

14821-
char name[256];
14822-
int numWritten = sprintf_s(name, ARRAY_SIZE(name), "IL_STUB_AsyncResume_%s_%s", m_pMethodBeingCompiled->GetName(), optimizationTierName);
14823-
if (numWritten != -1)
14824-
{
14825-
AllocMemTracker amTracker;
14826-
void* allocedMem = amTracker.Track(m_pMethodBeingCompiled->GetLoaderAllocator()->GetLowFrequencyHeap()->AllocMem(S_SIZE_T(numWritten + 1)));
14827-
memcpy(allocedMem, name, (size_t)(numWritten + 1));
14828-
result->AsDynamicMethodDesc()->SetMethodName((LPCUTF8)allocedMem);
14829-
amTracker.SuppressRelease();
14830-
}
14831-
1483214821
#ifdef _DEBUG
14833-
LOG((LF_STUBS, LL_INFO1000, "ASYNC: Resumption stub %s created\n", name));
14822+
LPCUTF8 methodName = m_pMethodBeingCompiled->GetName();
14823+
size_t stubNameLen = STRING_LENGTH("IL_STUB_AsyncResume__");
14824+
stubNameLen += strlen(methodName);
14825+
stubNameLen += strlen(optimizationTierName);
14826+
stubNameLen++; // "\n"
14827+
14828+
AllocMemTracker amTrackerName;
14829+
char* allocedMem = (char*)amTrackerName.Track(m_pMethodBeingCompiled->GetLoaderAllocator()->GetLowFrequencyHeap()->AllocMem(S_SIZE_T(stubNameLen)));
14830+
sprintf_s(allocedMem, stubNameLen, "IL_STUB_AsyncResume_%s_%s", m_pMethodBeingCompiled->GetName(), optimizationTierName);
14831+
result->AsDynamicMethodDesc()->SetMethodName((LPCUTF8)allocedMem);
14832+
amTrackerName.SuppressRelease();
14833+
14834+
LOG((LF_STUBS, LL_INFO1000, "ASYNC: Resumption stub %s created\n", allocedMem));
1483414835
sl.LogILStub(CORJIT_FLAGS());
1483514836
#endif
1483614837

0 commit comments

Comments
 (0)