From 7b885fddf496551f8afbce1c03f76bae4be5252d Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Thu, 27 Jun 2024 15:16:11 -0700 Subject: [PATCH 1/3] Add NULL checks to GetClassWithPossibleAV --- src/coreclr/vm/methodtable.inl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/methodtable.inl b/src/coreclr/vm/methodtable.inl index a63b95027ba3df..bcc7fe75be756c 100644 --- a/src/coreclr/vm/methodtable.inl +++ b/src/coreclr/vm/methodtable.inl @@ -29,7 +29,12 @@ FORCEINLINE PTR_EEClass MethodTable::GetClassWithPossibleAV() LIMITED_METHOD_DAC_CONTRACT; TADDR addr = m_pCanonMT; - +#ifdef DACCESS_COMPILE + if (addr == NULL) + { + DacError(E_UNEXPECTED); + } +#endif LowBits lowBits = union_getLowBits(addr); if (lowBits == UNION_EECLASS) { @@ -39,6 +44,12 @@ FORCEINLINE PTR_EEClass MethodTable::GetClassWithPossibleAV() { // pointer to canonical MethodTable. TADDR canonicalMethodTable = union_getPointer(addr); +#ifdef DACCESS_COMPILE + if (canonicalMethodTable == NULL) + { + DacError(E_UNEXPECTED); + } +#endif // a canonical method table always points at its EEClass, and m_pEEClass has no mask bit, so just return it return PTR_MethodTable(canonicalMethodTable)->m_pEEClass; } From 09e50f562572653401a1d33a89baa2017224aa52 Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Thu, 27 Jun 2024 16:33:36 -0700 Subject: [PATCH 2/3] Fix build break; linux_musl-x64 defines NULL as std::nullptr_t --- src/coreclr/vm/methodtable.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/methodtable.inl b/src/coreclr/vm/methodtable.inl index bcc7fe75be756c..1ce1f2e98c3977 100644 --- a/src/coreclr/vm/methodtable.inl +++ b/src/coreclr/vm/methodtable.inl @@ -30,7 +30,7 @@ FORCEINLINE PTR_EEClass MethodTable::GetClassWithPossibleAV() TADDR addr = m_pCanonMT; #ifdef DACCESS_COMPILE - if (addr == NULL) + if (addr == 0) { DacError(E_UNEXPECTED); } @@ -45,7 +45,7 @@ FORCEINLINE PTR_EEClass MethodTable::GetClassWithPossibleAV() // pointer to canonical MethodTable. TADDR canonicalMethodTable = union_getPointer(addr); #ifdef DACCESS_COMPILE - if (canonicalMethodTable == NULL) + if (canonicalMethodTable == 0) { DacError(E_UNEXPECTED); } From 5f6dd99d868c00994db2bf198ff2075b013a90e3 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 27 Jun 2024 16:36:48 -0700 Subject: [PATCH 3/3] Apply suggestions from code review --- src/coreclr/vm/methodtable.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/vm/methodtable.inl b/src/coreclr/vm/methodtable.inl index 1ce1f2e98c3977..4557c652b213bc 100644 --- a/src/coreclr/vm/methodtable.inl +++ b/src/coreclr/vm/methodtable.inl @@ -30,7 +30,7 @@ FORCEINLINE PTR_EEClass MethodTable::GetClassWithPossibleAV() TADDR addr = m_pCanonMT; #ifdef DACCESS_COMPILE - if (addr == 0) + if (addr == (TADDR)NULL) { DacError(E_UNEXPECTED); } @@ -45,7 +45,7 @@ FORCEINLINE PTR_EEClass MethodTable::GetClassWithPossibleAV() // pointer to canonical MethodTable. TADDR canonicalMethodTable = union_getPointer(addr); #ifdef DACCESS_COMPILE - if (canonicalMethodTable == 0) + if (canonicalMethodTable == (TADDR)NULL) { DacError(E_UNEXPECTED); }