runtime icon indicating copy to clipboard operation
runtime copied to clipboard

[X86 Profiling] Call of FireEtwMethodLoadVerbose_V1 from ETW::MethodLog::SendHelperEvent with NULL parameters causes segfault on X86 in memcpy

Open sergign60 opened this issue 9 years ago • 4 comments

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?

sergign60 avatar May 04 '17 08:05 sergign60

CC: @Dmitri-Botcharnikov @lucenticus

sergign60 avatar May 04 '17 08:05 sergign60

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;
 }

sergign60 avatar May 04 '17 09:05 sergign60

https://github.com/dotnet/coreclr/pull/11385

sergign60 avatar May 04 '17 11:05 sergign60

Fixed via dotnet/coreclr#11385.

brianrob avatar May 05 '17 15:05 brianrob