https://github.com/python/cpython/commit/8a6a6f39c869a6601babc31592e156ce22478a47 commit: 8a6a6f39c869a6601babc31592e156ce22478a47 branch: 3.14 author: Victor Stinner <vstin...@python.org> committer: vstinner <vstin...@python.org> date: 2025-05-27T16:13:20Z summary:
[3.14] gh-134744: Fix fcntl error handling (#134748) (#134795) gh-134744: Fix fcntl error handling (#134748) Fix also reference leak on buffer overflow. (cherry picked from commit 9300a596d37d058e6e58d00a2ad70617c863a3de) files: M Lib/test/test_fcntl.py M Lib/test/test_ioctl.py diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py index b84c98ef3a2972..0570257c5230d5 100644 --- a/Lib/test/test_fcntl.py +++ b/Lib/test/test_fcntl.py @@ -11,7 +11,7 @@ cpython_only, get_pagesize, is_apple, requires_subprocess, verbose ) from test.support.import_helper import import_module -from test.support.os_helper import TESTFN, unlink +from test.support.os_helper import TESTFN, unlink, make_bad_fd # Skip test if no fcntl module. @@ -228,6 +228,15 @@ def test_fcntl_f_pipesize(self): os.close(test_pipe_r) os.close(test_pipe_w) + @unittest.skipUnless(hasattr(fcntl, 'F_DUPFD'), 'need fcntl.F_DUPFD') + def test_bad_fd(self): + # gh-134744: Test error handling + fd = make_bad_fd() + with self.assertRaises(OSError): + fcntl.fcntl(fd, fcntl.F_DUPFD, 0) + with self.assertRaises(OSError): + fcntl.fcntl(fd, fcntl.F_DUPFD, b'\0' * 1024) + if __name__ == '__main__': unittest.main() diff --git a/Lib/test/test_ioctl.py b/Lib/test/test_ioctl.py index 7a986048bdac2a..01e1bfb42dd986 100644 --- a/Lib/test/test_ioctl.py +++ b/Lib/test/test_ioctl.py @@ -5,7 +5,7 @@ import threading import unittest from test import support -from test.support import threading_helper +from test.support import os_helper, threading_helper from test.support.import_helper import import_module fcntl = import_module('fcntl') termios = import_module('termios') @@ -202,6 +202,15 @@ def test_ioctl_set_window_size(self): new_winsz = struct.unpack("HHHH", result) self.assertEqual(new_winsz[:2], (20, 40)) + @unittest.skipUnless(hasattr(fcntl, 'FICLONE'), 'need fcntl.FICLONE') + def test_bad_fd(self): + # gh-134744: Test error handling + fd = os_helper.make_bad_fd() + with self.assertRaises(OSError): + fcntl.ioctl(fd, fcntl.FICLONE, fd) + with self.assertRaises(OSError): + fcntl.ioctl(fd, fcntl.FICLONE, b'\0' * 1024) + if __name__ == "__main__": unittest.main() _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: arch...@mail-archive.com