Skip to content

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

Open
aisk wants to merge 2 commits intopython:mainfrom
aisk:pathconf-with-negative-one
Open

gh-145335: Fix crash when passing -1 as fd in os.pathconf#145390
aisk wants to merge 2 commits intopython:mainfrom
aisk:pathconf-with-negative-one

Conversation

@aisk
Copy link
Member

@aisk aisk commented Mar 1, 2026

We currently test whether path_t.fd is -1 to decide if the argument should be treated as an fd or as a path, and then call fpathconf() or pathconf() according to it.

In the original issue, we passing -1 caused the code incorrectly treats the argument as a real path. But, path->narrow is NULL, so calling pathconf() on it will crash the interpreter.

This change adds a helper that checks whether the original argument is index-like to determine if it's an fd, so we can correctly the behavior and avoid the crash.

There are other os functions that accept path_t and may have the same issue. Since that is outside the scope of the original issue, I think we should fix those in a separate PR.

static bool
path_is_fd(const path_t *path)
{
return path->allow_fd && path->object != NULL && PyIndex_Check(path->object);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the problem really with the check or with is it with the converter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: nvm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants