[3.12] gh-122334: Fix crash when importing ssl after re-initialization (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.
This commit is contained in:
neonene 2024-08-02 22:44:55 +09:00 committed by GitHub
parent 372df19508
commit 6b8a9a1061
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 0 deletions

View file

@ -2071,6 +2071,18 @@ parser_clear(struct _PyArg_Parser *parser)
if (parser->initialized == 1) {
Py_CLEAR(parser->kwtuple);
}
if (parser->format) {
parser->fname = NULL;
}
else {
assert(parser->fname != NULL);
}
parser->custom_msg = NULL;
parser->pos = 0;
parser->min = 0;
parser->max = 0;
parser->initialized = 0;
}
static PyObject*