Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-145335: Fix crash when passing -1 as fd in os.pathconf#145390

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

Merged
vstinner merged 4 commits intopython:mainfromaisk:pathconf-with-negative-one
Mar 2, 2026
Merged
Show file tree
Hide file tree
Changes fromall 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
10 changes: 10 additions & 0 deletionsLib/test/test_os/test_os.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2778,6 +2778,16 @@ def test_fpathconf_bad_fd(self):
self.check(os.pathconf, "PC_NAME_MAX")
self.check(os.fpathconf, "PC_NAME_MAX")

@unittest.skipUnless(hasattr(os, 'pathconf'), 'test needs os.pathconf()')
@unittest.skipIf(
support.linked_to_musl(),
'musl fpathconf ignores the file descriptor and returns a constant',
)
def test_pathconf_negative_fd_uses_fd_semantics(self):
with self.assertRaises(OSError) as ctx:
os.pathconf(-1, 1)
self.assertEqual(ctx.exception.errno, errno.EBADF)

@unittest.skipUnless(hasattr(os, 'ftruncate'), 'test needs os.ftruncate()')
def test_ftruncate(self):
self.check(os.truncate, 0)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Fix a crash in :func:`os.pathconf` when called with ``-1`` as the path
argument.
9 changes: 7 additions & 2 deletionsModules/posixmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1280,6 +1280,8 @@ get_posix_state(PyObject *module)
* Contains a file descriptor if path.accept_fd was true
* and the caller provided a signed integer instead of any
* sort of string.
* path.is_fd
* True if path was provided as a file descriptor.
*
* WARNING: if your "path" parameter is optional, and is
* unspecified, path_converter will never get called.
Expand DownExpand Up@@ -1332,6 +1334,7 @@ typedef struct {
const wchar_t *wide;
const char *narrow;
int fd;
bool is_fd;
int value_error;
Py_ssize_t length;
PyObject *object;
Expand All@@ -1341,7 +1344,7 @@ typedef struct {
#define PATH_T_INITIALIZE(function_name, argument_name, nullable, nonstrict, \
make_wide, suppress_value_error, allow_fd) \
{function_name, argument_name, nullable, nonstrict, make_wide, \
suppress_value_error, allow_fd, NULL, NULL, -1, 0, 0, NULL, NULL}
suppress_value_error, allow_fd, NULL, NULL, -1,false,0, 0, NULL, NULL}
#ifdef MS_WINDOWS
#define PATH_T_INITIALIZE_P(function_name, argument_name, nullable, \
nonstrict, suppress_value_error, allow_fd) \
Expand DownExpand Up@@ -1475,6 +1478,7 @@ path_converter(PyObject *o, void *p)
}
path->wide = NULL;
path->narrow = NULL;
path->is_fd = true;
goto success_exit;
}
else {
Expand DownExpand Up@@ -14328,8 +14332,9 @@ os_pathconf_impl(PyObject *module, path_t *path, int name)

errno = 0;
#ifdef HAVE_FPATHCONF
if (path->fd != -1)
if (path->is_fd) {
limit = fpathconf(path->fd, name);
}
else
#endif
limit = pathconf(path->narrow, name);
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp