diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-19 12:26:26 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-19 12:26:26 +0200 |
commit | 441d30fac7f4037e4a79e4ada873de3b6f6e5a26 (patch) | |
tree | a406cb41f1b78476445786f408b95b1cd0bdb7a6 /Lib/test/test_fcntl.py | |
parent | ff12fae80e15ad29ae2557d23e70f6ff9365b31f (diff) | |
download | cpython-git-441d30fac7f4037e4a79e4ada873de3b6f6e5a26.tar.gz |
Issue #15989: Fix several occurrences of integer overflow
when result of PyLong_AsLong() narrowed to int without checks.
This is a backport of changesets 13e2e44db99d and 525407d89277.
Diffstat (limited to 'Lib/test/test_fcntl.py')
-rw-r--r-- | Lib/test/test_fcntl.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index 29af99cf16..0ce3a5dd7a 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -6,6 +6,7 @@ OS/2+EMX doesn't support the file locking operations. import os import struct import sys +import _testcapi import unittest from test.support import verbose, TESTFN, unlink, run_unittest, import_module @@ -76,6 +77,26 @@ class TestFcntl(unittest.TestCase): rv = fcntl.fcntl(self.f, fcntl.F_SETLKW, lockdata) self.f.close() + def test_fcntl_bad_file(self): + class F: + def __init__(self, fn): + self.fn = fn + def fileno(self): + return self.fn + self.assertRaises(ValueError, fcntl.fcntl, -1, fcntl.F_SETFL, os.O_NONBLOCK) + self.assertRaises(ValueError, fcntl.fcntl, F(-1), fcntl.F_SETFL, os.O_NONBLOCK) + self.assertRaises(TypeError, fcntl.fcntl, 'spam', fcntl.F_SETFL, os.O_NONBLOCK) + self.assertRaises(TypeError, fcntl.fcntl, F('spam'), fcntl.F_SETFL, os.O_NONBLOCK) + # Issue 15989 + self.assertRaises(OverflowError, fcntl.fcntl, _testcapi.INT_MAX + 1, + fcntl.F_SETFL, os.O_NONBLOCK) + self.assertRaises(OverflowError, fcntl.fcntl, F(_testcapi.INT_MAX + 1), + fcntl.F_SETFL, os.O_NONBLOCK) + self.assertRaises(OverflowError, fcntl.fcntl, _testcapi.INT_MIN - 1, + fcntl.F_SETFL, os.O_NONBLOCK) + self.assertRaises(OverflowError, fcntl.fcntl, F(_testcapi.INT_MIN - 1), + fcntl.F_SETFL, os.O_NONBLOCK) + def test_fcntl_64_bit(self): # Issue #1309352: fcntl shouldn't fail when the third arg fits in a # C 'long' but not in a C 'int'. |