From 7e6c44f55c5a49935ec014edbf94956d0f097c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Tue, 18 Feb 2020 12:32:07 +0000 Subject: [PATCH] Fix GetInteropNativeAssemblies (#1556) --- src/CLR/Debugger/Debugger.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/CLR/Debugger/Debugger.cpp b/src/CLR/Debugger/Debugger.cpp index c600a66ba9..d646416ef3 100644 --- a/src/CLR/Debugger/Debugger.cpp +++ b/src/CLR/Debugger/Debugger.cpp @@ -1141,11 +1141,15 @@ static bool GetInteropNativeAssemblies( uint8_t* &data, int* size, uint32_t star // - if 0, adjust to the assemblies count to make the execution backwards compatible // - trim if over the available assembly count // (max possible page size is 255) - if( count == 0 || - count > 255 || - (count + startIndex) > nativeAssembliesCount) + if(startIndex == 0 && count == 0) { // adjust to the assemblies count to make the execution backwards compatible + count = nativeAssembliesCount; + } + else if(count > 255 || + count + startIndex > nativeAssembliesCount) + { + // adjust to the assemblies count so it doesn't overflow count = nativeAssembliesCount - startIndex; } @@ -1158,7 +1162,7 @@ static bool GetInteropNativeAssemblies( uint8_t* &data, int* size, uint32_t star return false; } - // clear memory + // clear buffer memory memset( interopNativeAssemblies, 0, @@ -1172,7 +1176,7 @@ static bool GetInteropNativeAssemblies( uint8_t* &data, int* size, uint32_t star // we have an assembly at this position // check if it's on the requested range if( i >= startIndex && - i <= (startIndex + count)) + i < (startIndex + count)) { interopNativeAssemblies[index].CheckSum = g_CLR_InteropAssembliesNativeData[i]->m_checkSum; hal_strcpy_s((char*)interopNativeAssemblies[index].AssemblyName, ARRAYSIZE(interopNativeAssemblies[index].AssemblyName), g_CLR_InteropAssembliesNativeData[i]->m_szAssemblyName); @@ -1187,8 +1191,10 @@ static bool GetInteropNativeAssemblies( uint8_t* &data, int* size, uint32_t star } } + // copy back the buffer data = (uint8_t*)interopNativeAssemblies; + // set buffer size *size = (sizeof(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapabilities::NativeAssemblyDetails) * count); return true;