Skip to content

Commit 7410402

Browse files
[3.13] gh-134744: Fix fcntl error handling (GH-134748) (GH-134795) (#134798)
[3.14] gh-134744: Fix fcntl error handling (GH-134748) (GH-134795) gh-134744: Fix fcntl error handling (GH-134748) Fix also reference leak on buffer overflow. (cherry picked from commit 8a6a6f3) (cherry picked from commit 9300a59) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent 067df2b commit 7410402

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Lib/test/test_fcntl.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
cpython_only, get_pagesize, is_apple, requires_subprocess, verbose
1212
)
1313
from test.support.import_helper import import_module
14-
from test.support.os_helper import TESTFN, unlink
14+
from test.support.os_helper import TESTFN, unlink, make_bad_fd
1515

1616

1717
# Skip test if no fcntl module.
@@ -228,6 +228,15 @@ def test_fcntl_f_pipesize(self):
228228
os.close(test_pipe_r)
229229
os.close(test_pipe_w)
230230

231+
@unittest.skipUnless(hasattr(fcntl, 'F_DUPFD'), 'need fcntl.F_DUPFD')
232+
def test_bad_fd(self):
233+
# gh-134744: Test error handling
234+
fd = make_bad_fd()
235+
with self.assertRaises(OSError):
236+
fcntl.fcntl(fd, fcntl.F_DUPFD, 0)
237+
with self.assertRaises(OSError):
238+
fcntl.fcntl(fd, fcntl.F_DUPFD, b'\0' * 1024)
239+
231240

232241
if __name__ == '__main__':
233242
unittest.main()

Lib/test/test_ioctl.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import threading
66
import unittest
77
from test import support
8-
from test.support import threading_helper
8+
from test.support import os_helper, threading_helper
99
from test.support.import_helper import import_module
1010
fcntl = import_module('fcntl')
1111
termios = import_module('termios')
@@ -208,6 +208,15 @@ def test_ioctl_signed_unsigned_code_param(self):
208208
new_winsz = fcntl.ioctl(self.master_fd, set_winsz_opcode_pos, our_winsz)
209209
new_winsz = fcntl.ioctl(self.master_fd, set_winsz_opcode_maybe_neg, our_winsz)
210210

211+
@unittest.skipUnless(hasattr(fcntl, 'FICLONE'), 'need fcntl.FICLONE')
212+
def test_bad_fd(self):
213+
# gh-134744: Test error handling
214+
fd = os_helper.make_bad_fd()
215+
with self.assertRaises(OSError):
216+
fcntl.ioctl(fd, fcntl.FICLONE, fd)
217+
with self.assertRaises(OSError):
218+
fcntl.ioctl(fd, fcntl.FICLONE, b'\0' * 1024)
219+
211220

212221
if __name__ == "__main__":
213222
unittest.main()

0 commit comments

Comments
 (0)