Port to 3.1 - Fix out of range access in GetRecycleMemoryInfo (#27959)
[platform/upstream/coreclr.git] / src / vm / win32threadpool.h
index e05849e..f3fe62f 100644 (file)
@@ -749,7 +749,9 @@ public:
 #else // !FEATURE_PAL
             if (PAL_HasGetCurrentProcessorNumber())
             {
-                processorNumber = GetCurrentProcessorNumber();
+                // On linux, GetCurrentProcessorNumber which uses sched_getcpu() can return a value greater than the number
+                // of processors reported by sysconf(_SC_NPROCESSORS_ONLN) when using OpenVZ kernel.
+                processorNumber = GetCurrentProcessorNumber()%NumberOfProcessors;
             }
 #endif // !FEATURE_PAL
             return pRecycledListPerProcessor[processorNumber][memType];