diff --git a/src/Microsoft.Diagnostics.Runtime/DacInterface/SosDac.cs b/src/Microsoft.Diagnostics.Runtime/DacInterface/SosDac.cs index 273f05036..156bee210 100644 --- a/src/Microsoft.Diagnostics.Runtime/DacInterface/SosDac.cs +++ b/src/Microsoft.Diagnostics.Runtime/DacInterface/SosDac.cs @@ -295,6 +295,12 @@ public string GetFrameName(ulong vtable) public HResult GetFieldInfo(ulong mt, out MethodTableFieldInfo data) { + if (mt == 0) + { + data = default; + return HResult.E_INVALIDARG; + } + return VTable.GetMethodTableFieldData(Self, mt, out data); } @@ -420,6 +426,11 @@ public HResult GetAppDomainData(ulong addr, out AppDomainData data) public string? GetAppDomainName(ulong appDomain) { + if (appDomain == 0) + { + return null; + } + return GetString(VTable.GetAppDomainName, appDomain); } @@ -436,7 +447,7 @@ public HResult GetAppDomainStoreData(out AppDomainStoreData data) public HResult GetMethodTableData(ulong addr, out MethodTableData data) { // If the 2nd bit is set it means addr is actually a TypeHandle (which GetMethodTable does not support). - if ((addr & 2) == 2) + if (addr == 0 || (addr & 2) == 2) { data = default; return HResult.E_INVALIDARG; @@ -662,6 +673,9 @@ public enum ModuleMapTraverseKind public HResult TraverseModuleMap(ModuleMapTraverseKind mt, ulong module, ModuleMapTraverse traverse) { + if (module == 0) + return HResult.E_INVALIDARG; + HResult hr = VTable.TraverseModuleMap(Self, mt, module, Marshal.GetFunctionPointerForDelegate(traverse), IntPtr.Zero); GC.KeepAlive(traverse); return hr; @@ -688,6 +702,9 @@ public enum VCSHeapType public HResult TraverseStubHeap(ulong heap, VCSHeapType type, LoaderHeapTraverse callback) { + if (heap == 0) + return HResult.E_INVALIDARG; + HResult hr = VTable.TraverseVirtCallStubHeap(Self, heap, type, Marshal.GetFunctionPointerForDelegate(callback)); GC.KeepAlive(callback); return hr; diff --git a/src/Microsoft.Diagnostics.Runtime/DacInterface/SosDac8.cs b/src/Microsoft.Diagnostics.Runtime/DacInterface/SosDac8.cs index 122e2cf37..82a76f83f 100644 --- a/src/Microsoft.Diagnostics.Runtime/DacInterface/SosDac8.cs +++ b/src/Microsoft.Diagnostics.Runtime/DacInterface/SosDac8.cs @@ -24,6 +24,12 @@ public SOSDac8(DacLibrary library, IntPtr ptr) public HResult GetAssemblyLoadContext(ClrDataAddress methodTable, out ClrDataAddress assemblyLoadContext) { + if (methodTable == 0) + { + assemblyLoadContext = 0; + return HResult.E_INVALIDARG; + } + return VTable.GetAssemblyLoadContext(Self, methodTable, out assemblyLoadContext); }