mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Fix #8105. Add validation to mmap.mmap so invalid file descriptors
don't cause a crash on Windows.
This commit is contained in:
parent
0bccc185b4
commit
ea47eaa395
3 changed files with 19 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue