runtime
runtime copied to clipboard
[X86 Profiling] Call of FireEtwMethodLoadVerbose_V1 from ETW::MethodLog::SendHelperEvent with NULL parameters causes segfault on X86 in memcpy
The following call (src/vm/eventtrace.cpp)
VOID ETW::MethodLog::SendHelperEvent(ULONGLONG ullHelperStartAddress, ULONG ulHelperSize, LPCWSTR pHelperName)
{
WRAPPER_NO_CONTRACT;
if(pHelperName)
{
PCWSTR szDtraceOutput1=W("");
ULONG methodFlags = ETW::MethodLog::MethodStructs::JitHelperMethod; // helper flag set
FireEtwMethodLoadVerbose_V1(ullHelperStartAddress,
0,
ullHelperStartAddress,
ulHelperSize,
0,
methodFlags,
NULL,
pHelperName,
NULL,
GetClrInstanceId());
}
}
causes segmentation fault in memcpy because str is NULL
bin/obj/Linux.x86.Debug/Generated/eventprovider/lttng/eventprovhelpers.cpp
bool WriteToBuffer(PCWSTR str, char *&buffer, int& offset, int& size, bool &fixedBuffer)
{
int byteCount = (PAL_wcslen(str) + 1) * sizeof(*str);
if (offset + byteCount)
{
if (!ResizeBuffer(buffer, size, offset, size + byteCount, fixedBuffer))
return false;
}
memcpy(buffer + offset, str, byteCount);
offset += byteCount;
return true;
}
The simple changes NULL to W16_NULLSTRING in SendHelperEvent fix this problem Just now I can't check this problem on the other platforms. My question is are NULL arguments in SendHelperEvent correct?
CC: @Dmitri-Botcharnikov @lucenticus
The another proposed way is
iff --git a/src/scripts/genXplatLttng.py b/src/scripts/genXplatLttng.py
index bacf034..6ff74c9 100644
--- a/src/scripts/genXplatLttng.py
+++ b/src/scripts/genXplatLttng.py
@@ -613,9 +613,9 @@ bool WriteToBuffer(PCWSTR str, char *&buffer, int& offset, int& size, bool &fixe
if (!ResizeBuffer(buffer, size, offset, size + byteCount, fixedBuffer))
return false;
}
-
- memcpy(buffer + offset, str, byteCount);
- offset += byteCount;
+ if (!str) return true;
+ memcpy(buffer + offset, str, byteCount);
+ offset += byteCount;
return true;
}
https://github.com/dotnet/coreclr/pull/11385
Fixed via dotnet/coreclr#11385.