diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-02-04 12:57:16 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-02-04 12:57:16 +0200 |
commit | b6a53404b782c74bd9f7817ddb97f33642146d0c (patch) | |
tree | 79d7604ba115755b16ce1afe9c555c2f745482aa /Lib | |
parent | a4409c18eb55e3e76110af1ac88d8a8f6001d42f (diff) | |
parent | 1d0bb9c8f97b0f4fc6717f73555576f523965e42 (diff) | |
download | cpython-git-b6a53404b782c74bd9f7817ddb97f33642146d0c.tar.gz |
Issue #6083: Fix multiple segmentation faults occured when PyArg_ParseTuple
parses nested mutating sequence.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ctypes/test/test_returnfuncptrs.py | 28 | ||||
-rw-r--r-- | Lib/test/test_functools.py | 22 | ||||
-rw-r--r-- | Lib/test/test_resource.py | 17 |
3 files changed, 65 insertions, 2 deletions
diff --git a/Lib/ctypes/test/test_returnfuncptrs.py b/Lib/ctypes/test/test_returnfuncptrs.py index af1caddaab..21cb843fed 100644 --- a/Lib/ctypes/test/test_returnfuncptrs.py +++ b/Lib/ctypes/test/test_returnfuncptrs.py @@ -33,5 +33,33 @@ class ReturnFuncPtrTestCase(unittest.TestCase): self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0) self.assertRaises(TypeError, strchr, b"abcdef") + def test_from_dll(self): + dll = CDLL(_ctypes_test.__file__) + # _CFuncPtr instances are now callable with a tuple argument + # which denotes a function name and a dll: + strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(("strchr", dll)) + self.assertTrue(strchr(b"abcdef", b"b"), "bcdef") + self.assertEqual(strchr(b"abcdef", b"x"), None) + self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0) + self.assertRaises(TypeError, strchr, b"abcdef") + + # Issue 6083: Reference counting bug + def test_test_from_dll_refcount(self): + class BadSequence(tuple): + def __getitem__(self, key): + if key == 0: + return "strchr" + if key == 1: + return CDLL(_ctypes_test.__file__) + raise IndexError + + # _CFuncPtr instances are now callable with a tuple argument + # which denotes a function name and a dll: + strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(BadSequence(("strchr", CDLL(_ctypes_test.__file__)))) + self.assertTrue(strchr(b"abcdef", b"b"), "bcdef") + self.assertEqual(strchr(b"abcdef", b"x"), None) + self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0) + self.assertRaises(TypeError, strchr, b"abcdef") + if __name__ == "__main__": unittest.main() diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index 828673c65a..30d7fb6b0c 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -194,7 +194,25 @@ class TestPartial(object): self.assertEqual(signature(f), signature(f_copy)) class TestPartialC(BaseTestC, TestPartial): - pass + + # Issue 6083: Reference counting bug + def test_setstate_refcount(self): + class BadSequence: + def __len__(self): + return 4 + def __getitem__(self, key): + if key == 0: + return max + elif key == 1: + return tuple(range(1000000)) + elif key in (2, 3): + return {} + raise IndexError + + f = self.partial(object) + self.assertRaisesRegex(SystemError, + "new style getargs format but argument is not a tuple", + f.__setstate__, BadSequence()) class TestPartialPy(BaseTestPy, TestPartial): @@ -204,7 +222,7 @@ class TestPartialPy(BaseTestPy, TestPartial): def test_repr(self): raise unittest.SkipTest("Python implementation of partial uses own repr") -class TestPartialCSubclass(BaseTestC, TestPartial): +class TestPartialCSubclass(TestPartialC): class PartialSubclass(c_functools.partial): pass diff --git a/Lib/test/test_resource.py b/Lib/test/test_resource.py index 0240c69834..bb3ff25a6a 100644 --- a/Lib/test/test_resource.py +++ b/Lib/test/test_resource.py @@ -107,6 +107,23 @@ class ResourceTest(unittest.TestCase): except (ValueError, AttributeError): pass + # Issue 6083: Reference counting bug + def test_setrusage_refcount(self): + try: + limits = resource.getrlimit(resource.RLIMIT_CPU) + except AttributeError: + pass + else: + class BadSequence: + def __len__(self): + return 2 + def __getitem__(self, key): + if key in (0, 1): + return len(tuple(range(1000000))) + raise IndexError + + resource.setrlimit(resource.RLIMIT_CPU, BadSequence()) + def test_main(verbose=None): support.run_unittest(ResourceTest) |