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

Merged
vstinner merged 4 commits intopython:mainfrom
aisk:pathconf-with-negative-one
Mar 2, 2026
Merged

gh-145335: Fix crash when passing -1 as fd in os.pathconf#145390
vstinner merged 4 commits intopython:mainfrom
aisk:pathconf-with-negative-one

Conversation

@aisk
Copy link
Member

@aiskaisk commentedMar 1, 2026
edited
Loading

We currently test whetherpath_t.fd is -1 to decide if the argument should be treated as an fd or as a path, and then callfpathconf() orpathconf() 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 callingpathconf() 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 otheros functions that acceptpath_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

Copy link
Member

Choose a reason for hiding this comment

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

Instead of checkingpath->object type (PyIndex_Check()), I would prefer adding apath_t.is_fd member and modifypath_converter() to set this member.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Updated.

@vstinner
Copy link
Member

Other functions have the same issues, even if they don't crash:

  • os.stat(-1)
  • os.statx(-1, mask=0)
  • os.chdir(-1)
  • os.chmod(-1, 0)
  • os.chown(-1, 0, 0)
  • os.listdir(-1): current it behaves asos.listdir(os.path.curdir)
  • os._path_exists(-1) (Windows only)
  • os._path_lexists(-1) (Windows only)
  • os._path_isdir(-1) (Windows only)
  • os._path_isfile(-1) (Windows only)
  • os._path_islink(-1) (Windows only)
  • os._path_isjunction(-1) (Windows only)
  • os.utime(-1, (0, 0))
  • os.execve(-1, ['/bin/true'], os.environ)
  • os.truncate(-1, 0)
  • os.statvfs(-1)
  • os.pathconf(-1, "PC_NAME_MAX") crash (issueSegfault from runningos.pathconf(-1, 1) #145335)
  • os.getxattr(-1, "user")
  • os.setxattr(-1, "user", b"1")
  • os.removexattr(-1, "user")
  • os.listxattr(-1): current it behaves asos.listxattr(os.path.curdir)
  • os.scandir(-1): current it behaves asos.scandir(os.path.curdir)

On Linux (with the glibc), most functions fail withOSError: [Errno 14] Bad address: -1.

This list are functions usingpath_t(allow_fd=True) type in Argument Clinic, or variants such aspath_t(allow_fd='PATH_HAVE_FCHDIR') type.

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@vstinnervstinner merged commit5c3a47b intopython:mainMar 2, 2026
51 checks passed
@vstinnervstinner added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes labelsMar 2, 2026
@miss-islington-app
Copy link

Thanks@aisk for the PR, and@vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks@aisk for the PR, and@vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMar 2, 2026
…onGH-145390)(cherry picked from commit5c3a47b)Co-authored-by: AN Long <aisk@users.noreply.github.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMar 2, 2026
…onGH-145390)(cherry picked from commit5c3a47b)Co-authored-by: AN Long <aisk@users.noreply.github.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
@bedevere-app
Copy link

GH-145432 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelMar 2, 2026
@bedevere-app
Copy link

GH-145433 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelMar 2, 2026
@vstinner
Copy link
Member

Merged, thanks for your contribution@aisk.

I'm working on a fix for the other affected functions.

vstinner pushed a commit that referenced this pull requestMar 2, 2026
…145390) (#145432)gh-145335: Fix crash when passing -1 as fd in os.pathconf (GH-145390)(cherry picked from commit5c3a47b)Co-authored-by: AN Long <aisk@users.noreply.github.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
vstinner pushed a commit that referenced this pull requestMar 2, 2026
…145390) (#145433)gh-145335: Fix crash when passing -1 as fd in os.pathconf (GH-145390)(cherry picked from commit5c3a47b)Co-authored-by: AN Long <aisk@users.noreply.github.com>Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
@vstinner
Copy link
Member

I wrote#145439 to fix other os functions.

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

Reviewers

@picnixzpicnixzpicnixz left review comments

@vstinnervstinnervstinner approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@aisk@vstinner@picnixz

[8]ページ先頭

©2009-2026 Movatter.jp