From e84796546fd35b6d54505b27882002b55fa7c794 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Tue, 20 Dec 2022 00:32:35 -0800 Subject: [PATCH] Make DacValidateMD more resilient to invalid MethodDesc The DacValidateMD is not resilient to invalid MethodDesc that contains NULL in its m_pMethTab field. It was found when using the ClrMD in the BenchmarkDotNet disassembler code which is trying to find if some constants in the code represent MethodDesc so that it can dump the related method name. This change fixes it by checking the MethodTable after it is extracted from the MethodDesc. There are two values that are not translated between the target and the debugger sides - NULL and -1. So I have added handling both as invalid there. --- src/coreclr/debug/daccess/request.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coreclr/debug/daccess/request.cpp b/src/coreclr/debug/daccess/request.cpp index 65080489ad5e46..08e9b8265829bf 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -194,7 +194,12 @@ BOOL DacValidateMD(PTR_MethodDesc pMD) PTR_MethodTable pMethodTable = pMD->GetMethodTable(); // Standard fast check - if (!pMethodTable->ValidateWithPossibleAV()) + if ((pMethodTable == NULL) || dac_cast(pMethodTable) == (TADDR)-1) + { + retval = FALSE; + } + + if (retval && !pMethodTable->ValidateWithPossibleAV()) { retval = FALSE; }