Repository navigation
Importing ssl After Reinitializing Crashes #122334
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Activity
- addedtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump3.12only security fixesonly security fixes3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes
on Jul 26, 2024 The following command crashes as well:
_testembed test_repeated_init_exec "import _ssl; _ssl.txt2obj(txt='1.3')"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,
_PyArg_Fini()clearsparser->kwtupleonly: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
parser->once.vorparser->initializedthere will allowparser_init()to run again, which would work around the issue.Reacted by Eric Snowericsnowcurrently commented
on Jul 29, 2024 MemberAuthorMore actionsGood sleuthing!
Some buildbots fail the
test_embedwithout building_sslmodule.
https://buildbot.python.org/#/builders/1366/builds/1792I think there is nothing left to do here.
Reacted by Petr ViktorinIndeed. Thank you for the fix!
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
once.vwasn't reset to 0. Is it worth adding that test in thetest_embed?
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
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