summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_mmap.py
diff options
context:
space:
mode:
authorBrian Curtin <brian.curtin@gmail.com>2010-08-01 15:26:26 (GMT)
committerBrian Curtin <brian.curtin@gmail.com>2010-08-01 15:26:26 (GMT)
commitea47eaa3955db096bbf3e0204cce8e342d74a8ae (patch)
tree9a2e4afed436803f86f65f8c611b4ef09d403c73 /Lib/test/test_mmap.py
parent0bccc185b4d333a6c50c18c8d1d9916aca96a99c (diff)
downloadcpython-ea47eaa3955db096bbf3e0204cce8e342d74a8ae.zip
cpython-ea47eaa3955db096bbf3e0204cce8e342d74a8ae.tar.gz
cpython-ea47eaa3955db096bbf3e0204cce8e342d74a8ae.tar.bz2
Fix #8105. Add validation to mmap.mmap so invalid file descriptors
don't cause a crash on Windows.
Diffstat (limited to 'Lib/test/test_mmap.py')
-rw-r--r--Lib/test/test_mmap.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 68af00e..5906c02 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -1,6 +1,6 @@
from test.support import TESTFN, run_unittest, import_module
import unittest
-import os, re, itertools
+import os, re, itertools, socket
# Skip test if we can't import mmap.
mmap = import_module('mmap')
@@ -586,6 +586,17 @@ class MmapTests(unittest.TestCase):
pass
m.close()
+ def test_invalid_descriptor(self):
+ # socket file descriptors are valid, but out of range
+ # for _get_osfhandle, causing a crash when validating the
+ # parameters to _get_osfhandle.
+ s = socket.socket()
+ try:
+ with self.assertRaises(mmap.error):
+ m = mmap.mmap(s.fileno(), 10)
+ finally:
+ s.close()
+
def test_context_manager(self):
with mmap.mmap(-1, 10) as m:
self.assertFalse(m.closed)