Skip to content

[3.14] gh-134744: Fix fcntl error handling (#134748) #134795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Lib/test/test_fcntl.py
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 10 additions & 1 deletion Lib/test/test_ioctl.py
Original file line number Diff line number Diff line change
@@ -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()
Loading
Oops, something went wrong.

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant