Make DacValidateMD and DacValidateMethodTable more resilient (#90797)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Fri, 18 Aug 2023 18:11:07 +0000 (11:11 -0700)
committerGitHub <noreply@github.com>
Fri, 18 Aug 2023 18:11:07 +0000 (11:11 -0700)
Make both methods more resilient to the case of invalid MethodDesc
and MethodTable with value -1.

Close #90691

Co-authored-by: Jan Vorlicek <janvorli@microsoft.com>
src/coreclr/debug/daccess/request.cpp

index 868593f..114900f 100644 (file)
@@ -135,11 +135,17 @@ BOOL DacValidateEEClass(PTR_EEClass pEEClass)
 
 BOOL DacValidateMethodTable(PTR_MethodTable pMT, BOOL &bIsFree)
 {
+    bIsFree = FALSE;
+
+    if ((pMT == NULL) || dac_cast<TADDR>(pMT) == (TADDR)-1)
+    {
+        return FALSE;
+    }
+
     // Verify things are right.
     BOOL retval = FALSE;
     EX_TRY
     {
-        bIsFree = FALSE;
         if (HOST_CDADDR(pMT) == HOST_CDADDR(g_pFreeObjectMethodTable))
         {
             bIsFree = TRUE;
@@ -182,7 +188,7 @@ BadMethodTable: ;
 
 BOOL DacValidateMD(PTR_MethodDesc pMD)
 {
-    if (pMD == NULL)
+    if ((pMD == NULL) || dac_cast<TADDR>(pMD) == (TADDR)-1)
     {
         return FALSE;
     }