Avoid race condition by ensuring array index is evaluated before accessing the array
This commit is contained in:
committed by
James Newton-King
parent
659ebc3e5b
commit
18cc211d0e
@@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user