Title: gh-145335: validate file descriptor in os.fpathconf and os.pathconf by gourijain029-del · Pull Request #145341 · python/cpython · GitHub
Open Graph Title: gh-145335: validate file descriptor in os.fpathconf and os.pathconf by gourijain029-del · Pull Request #145341 · python/cpython
X Title: gh-145335: validate file descriptor in os.fpathconf and os.pathconf by gourijain029-del · Pull Request #145341 · python/cpython
Description: Problem Calling os.fpathconf(-1, name) or os.pathconf(-1, name) on macOS (and other platforms) caused a segmentation fault. The CPython implementation passed the negative file descriptor straight to the underlying fpathconf system call, which is undefined behavior and crashes the interpreter. Fix Added a guard in Modules/posixmodule.c ( os_fpathconf_impl ) that checks fd < 0. When the descriptor is negative, the function now raises a clear ValueError with the message “file descriptor cannot be negative” and returns -1 to signal the error. The existing error‑handling path (errno handling) remains unchanged for valid descriptors. Regression Test Introduced Lib/test/test_os_pathconf.py which verifies that both os.fpathconf(-1, 1) and os.pathconf(-1, 1) raise ValueError with the expected message. The test runs as part of the standard CPython test suite, ensuring the fix stays in place. Impact Eliminates a hard crash for a common misuse pattern. Provides a Python‑level exception that developers can catch, matching the behaviour of other os.* functions that validate file descriptors. No functional changes for valid descriptors; all existing semantics are preserved. Related Issue Fixes issue #145335 (segfault from os.pathconf(-1, 1)). Issue: gh-145335
Open Graph Description: Problem Calling os.fpathconf(-1, name) or os.pathconf(-1, name) on macOS (and other platforms) caused a segmentation fault. The CPython implementation passed the negative file descriptor straight t...
X Description: Problem Calling os.fpathconf(-1, name) or os.pathconf(-1, name) on macOS (and other platforms) caused a segmentation fault. The CPython implementation passed the negative file descriptor straight t...
Opengraph URL: https://github.com/python/cpython/pull/145341
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1a73c3cd-04b7-bc11-a208-6afbf8a9e50c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9E40:1F82C3:58EB33:779BA3:6A52F95E |
| html-safe-nonce | bd2e7093073d1d76c934620b2e6efabb65456974e934d0c2ca8dbc7c57111916 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTQwOjFGODJDMzo1OEVCMzM6Nzc5QkEzOjZBNTJGOTVFIiwidmlzaXRvcl9pZCI6IjUyNjUyMTcwOTE2MDMyMDAzNTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | aabc1e2deaac1efaf2c3e136849bf685cf32267c06ee368227dd0d93ecdcb19f |
| hovercard-subject-tag | pull_request:3338137449 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/145341/files |
| twitter:image | https://avatars.githubusercontent.com/u/235066236?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/235066236?s=400&v=4 |
| og:image:alt | Problem Calling os.fpathconf(-1, name) or os.pathconf(-1, name) on macOS (and other platforms) caused a segmentation fault. The CPython implementation passed the negative file descriptor straight t... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width