Make DacValidateMD more resilient to invalid MethodDesc (#79846)
authorJan Vorlicek <janvorli@microsoft.com>
Tue, 20 Dec 2022 18:23:25 +0000 (19:23 +0100)
committerGitHub <noreply@github.com>
Tue, 20 Dec 2022 18:23:25 +0000 (19:23 +0100)
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

index 6508048..08e9b82 100644 (file)
@@ -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<TADDR>(pMethodTable) == (TADDR)-1)
+        {
+            retval = FALSE;
+        }
+
+        if (retval && !pMethodTable->ValidateWithPossibleAV())
         {
             retval = FALSE;
         }