- Issue #13703: oCERT-2011-003: add -R command-line option and PYTHONHASHSEED

environment variable, to provide an opt-in way to protect against denial of
  service attacks due to hash collisions within the dict and set types.  Patch
  by David Malcolm, based on work by Victor Stinner.
This commit is contained in:
Barry Warsaw 2012-02-20 20:42:21 -05:00
parent f5a5beb339
commit 1e13eb084f
27 changed files with 706 additions and 152 deletions

View file

@ -6,7 +6,6 @@ import weakref
import operator
import copy
import pickle
import os
from random import randrange, shuffle
import sys
import collections
@ -688,6 +687,17 @@ class TestBasicOps(unittest.TestCase):
if self.repr is not None:
self.assertEqual(repr(self.set), self.repr)
def check_repr_against_values(self):
text = repr(self.set)
self.assertTrue(text.startswith('{'))
self.assertTrue(text.endswith('}'))
result = text[1:-1].split(', ')
result.sort()
sorted_repr_values = [repr(value) for value in self.values]
sorted_repr_values.sort()
self.assertEqual(result, sorted_repr_values)
def test_print(self):
fo = open(test_support.TESTFN, "wb")
try:
@ -837,6 +847,46 @@ class TestBasicOpsTriple(TestBasicOps):
self.length = 3
self.repr = None
#------------------------------------------------------------------------------
class TestBasicOpsString(TestBasicOps):
def setUp(self):
self.case = "string set"
self.values = ["a", "b", "c"]
self.set = set(self.values)
self.dup = set(self.values)
self.length = 3
def test_repr(self):
self.check_repr_against_values()
#------------------------------------------------------------------------------
class TestBasicOpsUnicode(TestBasicOps):
def setUp(self):
self.case = "unicode set"
self.values = [u"a", u"b", u"c"]
self.set = set(self.values)
self.dup = set(self.values)
self.length = 3
def test_repr(self):
self.check_repr_against_values()
#------------------------------------------------------------------------------
class TestBasicOpsMixedStringUnicode(TestBasicOps):
def setUp(self):
self.case = "string and bytes set"
self.values = ["a", "b", u"a", u"b"]
self.set = set(self.values)
self.dup = set(self.values)
self.length = 4
def test_repr(self):
with test_support.check_warnings():
self.check_repr_against_values()
#==============================================================================
def baditer():