Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-126108: Fix potential null pointer dereference in PySys_AddWarnOptionUnicode#126118
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ghost commentedOct 29, 2024 • edited by ghost
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by ghost
Uh oh!
There was an error while loading.Please reload this page.
Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Misc/NEWS.d/next/Security/2024-10-29-09-15-10.gh-issue-126108.eTIjHY.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
…eTIjHY.rstCo-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…OptionUnicode' of github.com:federicovalenso/cpython into bug/potential-null-pointer-dereference-in-PySys_AddWarnOptionUnicode
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
ZeroIntensity commentedOct 29, 2024
Typically, the convention in the C API is to fully disallow calling without the GIL, via |
…Sys_AddWarnOptionUnicode
picnixz 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 (conditioned to a question) cc@sobolevn
| if (tstate) { | ||
| _PyErr_Clear(tstate); | ||
| } | ||
| _PyErr_Clear(tstate); |
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.
I assume that there's no way to maketstate NULL in_PySys_AddWarnOptionWithError.
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.
I agree,assert is the way to go here. We should not call these functions in places wheretstate can beNULL (while interpreter startup / shutdown).
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.
Would it actually make sense to have_PyErr_Clear do this automatically?
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.
Ok, in that case, I would likePySys_AddWarnOptionUnicode to fail with a fatal error if called without the GIL. No-oping because of a null thread state isn't common at all in the C API.
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.
Should I do some other changes or leave as is?
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.
Should we also do it in_PySys_AddWarnOptionWithError? WDYT@ZeroIntensity?
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.
I thinkassert(tstate != NULL) is fine for the private API.
ZeroIntensity left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Two main changes here (my suggestions address both):
- Functions in the C API shouldn't no-op if called without the GIL. Instead, we typically use
_Py_EnsureTstateNotNULLto send a fatal error. - This function can clear the error state, so any prior exceptions are lost. It's a good idea to make sure that callers aren't doing that on debug builds.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
sobolevn 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
ZeroIntensity 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.
Thank you!
federicovalenso commentedNov 15, 2024
@ericsnowcurrently, please review the code :) |
federicovalenso commentedDec 3, 2024
@picnixz , can we merge this PR? Changes approved by all reviewers. |
Uh oh!
There was an error while loading.Please reload this page.
fad36bf intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@federicovalenso for the PR, and@kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…WarnOptionUnicode` (pythonGH-126118)(cherry picked from commitfad36bf)Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
GH-129520 is a backport of this pull request to the3.13 branch. |
…WarnOptionUnicode` (pythonGH-126118)(cherry picked from commitfad36bf)Co-authored-by: Valery Fedorenko <federicovalenso@gmail.com>
GH-129522 is a backport of this pull request to the3.12 branch. |
Sorry@federicovalenso and@kumaraditya303, I had trouble completing the backport. |
Uh oh!
There was an error while loading.Please reload this page.
PySys_AddWarnOptionUnicode#126108