Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.2k
gh-145335: Fix crash when passing -1 as fd in os.pathconf#145390
gh-145335: Fix crash when passing -1 as fd in os.pathconf#145390vstinner merged 4 commits intopython:mainfrom
Conversation
Modules/posixmodule.c Outdated
| static bool | ||
| path_is_fd(const path_t *path) | ||
| { | ||
| return path->allow_fd && path->object != NULL && PyIndex_Check(path->object); |
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.
Is the problem really with the check or with is it with the converter?
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.
edit: nvm
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.
Instead of checkingpath->object type (PyIndex_Check()), I would prefer adding apath_t.is_fd member and modifypath_converter() to set this member.
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.
Updated.
vstinner commentedMar 2, 2026
Other functions have the same issues, even if they don't crash:
On Linux (with the glibc), most functions fail with This list are functions using |
Uh oh!
There was an error while loading.Please reload this page.
vstinner left a comment
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
5c3a47b intopython:mainUh oh!
There was an error while loading.Please reload this page.
…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>
…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>
GH-145432 is a backport of this pull request to the3.13 branch. |
GH-145433 is a backport of this pull request to the3.14 branch. |
vstinner commentedMar 2, 2026
Merged, thanks for your contribution@aisk. I'm working on a fix for the other affected functions. |
vstinner commentedMar 2, 2026
I wrote#145439 to fix other os functions. |
Uh oh!
There was an error while loading.Please reload this page.
We currently test whether
path_t.fdis -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->narrowis 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 other
osfunctions that acceptpath_tand 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.os.pathconf(-1, 1)#145335