Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
gh-134744: Fix fcntl error handling#134748
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@serhiy-storchaka: It seems like only the main branch is affected. I wrote a patch adding tests but it doesn't check modified error paths: diff--gita/Lib/test/test_fcntl.pyb/Lib/test/test_fcntl.pyindexe0e6782258f..e1c72c6ab7e100644---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 )fromtest.support.import_helperimportimport_module-fromtest.support.os_helperimportTESTFN,unlink+fromtest.support.os_helperimportTESTFN,unlink,make_bad_fd# Skip test if no fcntl module.@@-274,6+274,13 @@deftest_fcntl_small_buffer(self):deftest_fcntl_large_buffer(self):self._check_fcntl_not_mutate_len(2024)+ @unittest.skipUnless(hasattr(fcntl,'FICLONE'),'need fcntl.FICLONE')+deftest_bad_fd(self):+# gh-134744: Test error handling+fd=make_bad_fd()+withself.assertRaises(OSError):+fcntl.ioctl(fd,fcntl.F_DUPFD,0)+if__name__=='__main__':unittest.main()diff--gita/Lib/test/test_ioctl.pyb/Lib/test/test_ioctl.pyindex3c7a58aa2bc..e2f94dbf5dd100644---a/Lib/test/test_ioctl.py+++b/Lib/test/test_ioctl.py@@-5,7+5,7 @@importthreadingimportunittestfromtestimportsupport-fromtest.supportimportthreading_helper+fromtest.supportimportos_helper,threading_helperfromtest.support.import_helperimportimport_modulefcntl=import_module('fcntl')termios=import_module('termios')@@-201,6+201,15 @@deftest_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')+deftest_bad_fd(self):+# gh-134744: Test error handling+withopen(__file__)asfp:+fd1=fp.fileno()+fd2=os_helper.make_bad_fd()+withself.assertRaises(OSError):+fcntl.ioctl(fd1,fcntl.FICLONE,fd2)+if__name__=="__main__":unittest.main() |
@vstinner It seems that on 139 and 321 lines it may leak. |
Would you mind to elaborate? What leak? In which file? |
Sorry, I was not clear. In Lines 130 to 141 in3c05251
As you can see result decrefed on 134, but not on 139 lines.Lines 312 to 323 in3c05251
Same here - it decrefed on 316, but not on 321. |
Thank you@vstinner. The code is the same in 3.14 and main, but 3.13 is not affected. It is my fail. For testing you need to pass a large bytes object (more than 1024 bytes). Simply pass Thank you@sergey-miryanov for noticing a leak. |
Ok, I added tests and I fixed the reference leak spotted by@sergey-miryanov. |
@serhiy-storchaka: Would you mind to review my fix? |
3.14 doesn't seem to be affected, the code is different. if (ret<0) {return !async_err ?PyErr_SetFromErrno(PyExc_OSError) :NULL; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM. 👍
Ah, so both bugs was introduced while adding a buffer overflow check. |
9300a59
intopython:mainUh oh!
There was an error while loading.Please reload this page.
It would be nice to backport the tests. |
Fix also reference leak on buffer overflow.(cherry picked from commit9300a59)
GH-134795 is a backport of this pull request to the3.14 branch. |
I wrote#134795 to backport tests. I had to modify tests since Python 3.14 only supports buffer up to 1024 bytes. |
…ythonGH-134795)pythongh-134744: Fix fcntl error handling (pythonGH-134748)Fix also reference leak on buffer overflow.(cherry picked from commit8a6a6f3)Co-authored-by: Victor Stinner <vstinner@python.org>(cherry picked from commit9300a59)
Uh oh!
There was an error while loading.Please reload this page.
_PyEval_EvalFrameDefault
originating on callingfcntl.ioctl
#134744