From 99a6d6b127cc79d671c6ed49b58cfeac3982da60 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 5d755b2bf556e6..0972249284582d 100644 --- a/src/coreclr/debug/daccess/request.cpp +++ b/src/coreclr/debug/daccess/request.cpp @@ -195,7 +195,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; }