Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions Lib/test/test_os/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,18 @@ def test_fstat(self):
finally:
fp.close()

@unittest.skipUnless(hasattr(posix, 'stat'),
'test needs posix.stat()')
@unittest.skipUnless(os.stat in os.supports_follow_symlinks,
'test needs follow_symlinks support in os.stat()')
def test_stat_fd_zero_follow_symlinks(self):
with self.assertRaisesRegex(ValueError,
'cannot use fd and follow_symlinks together'):
posix.stat(0, follow_symlinks=False)
with self.assertRaisesRegex(ValueError,
'cannot use fd and follow_symlinks together'):
posix.stat(1, follow_symlinks=False)

def check_statlike_path(self, func):
self.assertTrue(func(os_helper.TESTFN))
self.assertTrue(func(os.fsencode(os_helper.TESTFN)))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed validation of file descriptor 0 in posix functions when used with
follow_symlinks parameter.
2 changes: 1 addition & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ static int
fd_and_follow_symlinks_invalid(const char *function_name, int fd,
int follow_symlinks)
{
if ((fd > 0) && (!follow_symlinks)) {
if ((fd >= 0) && (!follow_symlinks)) {
PyErr_Format(PyExc_ValueError,
"%s: cannot use fd and follow_symlinks together",
function_name);
Expand Down
Loading