[Python-checkins] r83407 - in python/branches/py3k: Lib/test/test_mmap.py Misc/NEWS Modules/mmapmodule.c
brian.curtin
python-checkins at python.org
Sun Aug 1 17:26:26 CEST 2010
Author: brian.curtin
Date: Sun Aug 1 17:26:26 2010
New Revision: 83407
Log:
Fix #8105. Add validation to mmap.mmap so invalid file descriptors
don't cause a crash on Windows.
Modified:
python/branches/py3k/Lib/test/test_mmap.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Modules/mmapmodule.c
Modified: python/branches/py3k/Lib/test/test_mmap.py
==============================================================================
--- python/branches/py3k/Lib/test/test_mmap.py (original)
+++ python/branches/py3k/Lib/test/test_mmap.py Sun Aug 1 17:26:26 2010
@@ -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 @@
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)
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Sun Aug 1 17:26:26 2010
@@ -21,6 +21,8 @@
Extensions
----------
+- Issue #8105: Validate file descriptor passed to mmap.mmap on Windows.
+
- Issue #8046: Add context manager protocol support and .closed property
to mmap objects.
Modified: python/branches/py3k/Modules/mmapmodule.c
==============================================================================
--- python/branches/py3k/Modules/mmapmodule.c (original)
+++ python/branches/py3k/Modules/mmapmodule.c Sun Aug 1 17:26:26 2010
@@ -1236,6 +1236,11 @@
1);
*/
if (fileno != -1 && fileno != 0) {
+ /* Ensure that fileno is within the CRT's valid range */
+ if (_PyVerify_fd(fileno) == 0) {
+ PyErr_SetFromErrno(mmap_module_error);
+ return NULL;
+ }
fh = (HANDLE)_get_osfhandle(fileno);
if (fh==(HANDLE)-1) {
PyErr_SetFromErrno(mmap_module_error);
More information about the Python-checkins
mailing list