Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in monitored .NET process when an exception does not have a… #201

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions profiler/src/ProcDumpProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ String CorProfiler::GetExceptionMessage(ObjectID objectId)
}

//
// Loop to lcoate the "_message" field
// Loop to locate the "_message" field
// Get stringLength from the "_message" field stringLengthOffset
// Copy the number of (stringLength+1) WCHARs from the "_message" field stringBufferOffset to our stringBuffer
//
Expand All @@ -1251,18 +1251,24 @@ String CorProfiler::GetExceptionMessage(ObjectID objectId)
delete [] pFieldOffsets;
return WCHAR("");
}

msgField = *(PLONG_PTR)(((BYTE *)objectId) + pFieldOffsets[fieldIndex].ulOffset);
stringLength = *(PINT32)((BYTE *)msgField + stringLengthOffset);
stringBuffer = new WCHAR[stringLength+1];
if(stringBuffer==NULL)
if(msgField != NULL)
{
LOG(TRACE) << "CorProfiler::GetExceptionMessage: Failed memory allocation for stringBuffer";
if(metadata != NULL) metadata->Release();
delete [] pFieldOffsets;
return WCHAR("");;
stringLength = *(PINT32)((BYTE *)msgField + stringLengthOffset);
stringBuffer = new WCHAR[stringLength+1];
if(stringBuffer==NULL)
{
LOG(TRACE) << "CorProfiler::GetExceptionMessage: Failed memory allocation for stringBuffer";
if(metadata != NULL) metadata->Release();
delete [] pFieldOffsets;
return WCHAR("");;
}

memcpy(stringBuffer, (BYTE *)msgField+stringBufferOffset,(stringLength+1)*sizeof(WCHAR));
msg+=stringBuffer;
}
memcpy(stringBuffer, (BYTE *)msgField+stringBufferOffset,(stringLength+1)*sizeof(WCHAR));
msg+=stringBuffer;

break;
}
}
Expand Down