From dae6b0212644005575e55bb90874ea368200db4f Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Mon, 15 Jul 2024 18:16:45 -0700 Subject: [PATCH 1/2] Fix crash in createdump in DAC enum memory code --- src/coreclr/vm/excep.cpp | 15 +++++++++------ src/coreclr/vm/methodtable.inl | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index fcb86fc36c2940..46dd51b498e9d2 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -7954,13 +7954,16 @@ BOOL ExceptionTypeOverridesStackTraceGetter(PTR_MethodTable pMT) for (DWORD slot = g_pObjectClass->GetNumVirtuals(); slot < g_pExceptionClass->GetNumVirtuals(); slot++) { MethodDesc *pMD = g_pExceptionClass->GetMethodDescForSlot(slot); - LPCUTF8 name = pMD->GetName(); - - if (name != NULL && strcmp(name, "get_StackTrace") == 0) + if (pMD != nullptr) { - // see if the slot is overridden by pMT - MethodDesc *pDerivedMD = pMT->GetMethodDescForSlot(slot); - return (pDerivedMD != pMD); + LPCUTF8 name = pMD->GetName(); + + if (name != NULL && strcmp(name, "get_StackTrace") == 0) + { + // see if the slot is overridden by pMT + MethodDesc *pDerivedMD = pMT->GetMethodDescForSlot(slot); + return (pDerivedMD != pMD); + } } } diff --git a/src/coreclr/vm/methodtable.inl b/src/coreclr/vm/methodtable.inl index 37600f26440085..c6bed6826c8ecf 100644 --- a/src/coreclr/vm/methodtable.inl +++ b/src/coreclr/vm/methodtable.inl @@ -415,6 +415,10 @@ inline MethodDesc* MethodTable::GetMethodDescForSlot(DWORD slot) CONTRACTL_END; PCODE pCode = GetRestoredSlot(slot); + if (pCode == (PCODE)NULL) + { + return nullptr; + } // This is an optimization that we can take advantage of if we're trying to get the MethodDesc // for an interface virtual, since their slots usually point to stub. From 291f0112b675977c26cfa9d026af4a45b2bf3c91 Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Tue, 16 Jul 2024 10:21:32 -0700 Subject: [PATCH 2/2] Code review feedback --- src/coreclr/vm/excep.cpp | 4 ++-- src/coreclr/vm/methodtable.inl | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/coreclr/vm/excep.cpp b/src/coreclr/vm/excep.cpp index 46dd51b498e9d2..7acb54ee42e2c0 100644 --- a/src/coreclr/vm/excep.cpp +++ b/src/coreclr/vm/excep.cpp @@ -7953,7 +7953,7 @@ BOOL ExceptionTypeOverridesStackTraceGetter(PTR_MethodTable pMT) // find the slot corresponding to get_StackTrace for (DWORD slot = g_pObjectClass->GetNumVirtuals(); slot < g_pExceptionClass->GetNumVirtuals(); slot++) { - MethodDesc *pMD = g_pExceptionClass->GetMethodDescForSlot(slot); + MethodDesc *pMD = g_pExceptionClass->GetMethodDescForSlot_NoThrow(slot); if (pMD != nullptr) { LPCUTF8 name = pMD->GetName(); @@ -7961,7 +7961,7 @@ BOOL ExceptionTypeOverridesStackTraceGetter(PTR_MethodTable pMT) if (name != NULL && strcmp(name, "get_StackTrace") == 0) { // see if the slot is overridden by pMT - MethodDesc *pDerivedMD = pMT->GetMethodDescForSlot(slot); + MethodDesc *pDerivedMD = pMT->GetMethodDescForSlot_NoThrow(slot); return (pDerivedMD != pMD); } } diff --git a/src/coreclr/vm/methodtable.inl b/src/coreclr/vm/methodtable.inl index c6bed6826c8ecf..37600f26440085 100644 --- a/src/coreclr/vm/methodtable.inl +++ b/src/coreclr/vm/methodtable.inl @@ -415,10 +415,6 @@ inline MethodDesc* MethodTable::GetMethodDescForSlot(DWORD slot) CONTRACTL_END; PCODE pCode = GetRestoredSlot(slot); - if (pCode == (PCODE)NULL) - { - return nullptr; - } // This is an optimization that we can take advantage of if we're trying to get the MethodDesc // for an interface virtual, since their slots usually point to stub.