Avoid race condition by ensuring array index is evaluated before accessing the array

This commit is contained in:
David Cobbold
2018-07-29 12:00:13 +12:00
committed by James Newton-King
parent 659ebc3e5b
commit 18cc211d0e
+5 -1
View File
@@ -75,7 +75,11 @@ namespace Newtonsoft.Json
hashCode -= hashCode >> 17;
hashCode -= hashCode >> 11;
hashCode -= hashCode >> 5;
for (Entry entry = _entries[hashCode & _mask]; entry != null; entry = entry.Next)
// make sure index is evaluated before accessing _entries, otherwise potential race condition causing IndexOutOfRangeException
var index = hashCode & _mask;
for (Entry entry = _entries[index]; entry != null; entry = entry.Next)
{
if (entry.HashCode == hashCode && TextEquals(entry.Value, key, start, length))
{