-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Importing ssl After Reinitializing Crashes #122334
Comments
The following command crashes as well:
Related clinic code (actually unchanged since Python 3.5): static PyObject *
_ssl_txt2obj(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
...
static const char * const _keywords[] = {"txt", "name", NULL};
static _PyArg_Parser _parser = {
.keywords = _keywords,
.fname = "txt2obj",
.kwtuple = KWTUPLE, // KWTUPLE: NULL
};
...
args = _PyArg_UnpackKeywords(..., &_parser, ...); // segfault Python/getargs.c: PyObject * const *
_PyArg_UnpackKeywords(..., struct _PyArg_Parser *parser, ...)
{
PyObject *kwtuple;
...
if (parser_init(parser) < 0) { // set `parser->kwtuple` only once
return NULL;
}
kwtuple = parser->kwtuple; // get NULL after restarting interp
...
maxargs = posonly + (int)PyTuple_GET_SIZE(kwtuple); // segfault Currently, void
_PyArg_Fini(void)
{
struct _PyArg_Parser *tmp, *s = _PyRuntime.getargs.static_parsers;
while (s) {
tmp = s->next;
s->next = NULL;
parser_clear(s);
s = tmp;
}
_PyRuntime.getargs.static_parsers = NULL;
}
// 3.13+
static void
parser_clear(struct _PyArg_Parser *parser)
{
if (parser->is_kwtuple_owned) {
Py_CLEAR(parser->kwtuple);
}
}
// 3.12
static void
parser_clear(struct _PyArg_Parser *parser)
{
if (parser->initialized == 1) {
Py_CLEAR(parser->kwtuple);
}
} IIUC, clearing |
Good sleuthing! |
…pythonGH-122481) * Fix crash when importing ssl after re-initialization (cherry picked from commit 9fc1c99) Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
GH-122481) (#122495) Fix crash when importing ssl after re-initialization The current METH_FASTCALL|METH_KEYWORDS functions in a non-builtin module can cause segfaults after restarting the main interpreter, invoking _PyArg_UnpackKeywords() with an insufficiently cleared _PyArg_Parser struct. This patch fixes the invalidation of the static argument parsers.
Some buildbots fail the |
Co-authored-by: Wulian233 <1055917385@qq.com>
…honGH-122630) (cherry picked from commit 50b3603) Co-authored-by: neonene <53406459+neonene@users.noreply.github.com> Co-authored-by: Wulian233 <1055917385@qq.com>
…honGH-122630) (cherry picked from commit 50b3603) Co-authored-by: neonene <53406459+neonene@users.noreply.github.com> Co-authored-by: Wulian233 <1055917385@qq.com>
I think there is nothing left to do here. |
Indeed. Thank you for the fix! |
…python#122481) * Fix crash when importing ssl after re-initialization
…honGH-122630) Co-authored-by: Wulian233 <1055917385@qq.com>
This is the same issue of #121087 Thanks for fixing it! I tested the code on that issue and it is passing. In that case the problem was that the |
…python#122481) * Fix crash when importing ssl after re-initialization
…honGH-122630) Co-authored-by: Wulian233 <1055917385@qq.com>
Crash report
What happened?
Using 3.13b4 and main (5592399):
Using 3.12:
The 3.12 output implies a problem related to argument clinic and the kwarg names tuple that gets cached.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Output from running 'python -VV' on the command line:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: