Issue 36496: Local variables can be used uninitialized in _PyPreConfig_Read() (original) (raw)
In bpo-36301, in commit f72346c47537657a287a862305f65eb5d7594fbf, a couple possible uses of uninitialized variables were introduced into Python/preconfig.c.
In particular, in _PyPreConfig_Read(), along an error-handling path, the init_utf8_mode
and init_legacy_encoding
variables will be read uninitialized.
_PyInitError
_PyPreConfig_Read(_PyPreConfig *config, const _PyArgv *args)
{
/* ... */
if (args) {
err = _PyPreCmdline_SetArgv(&cmdline, args);
if (_Py_INIT_FAILED(err)) {
goto done; /* ERROR HANDLING DONE HERE */
}
}
int init_utf8_mode = Py_UTF8Mode; /* VARIABLE INITIZLIED HERE */
#ifdef MS_WINDOWS
int init_legacy_encoding = Py_LegacyWindowsFSEncodingFlag; /* VARIABLE INITIZLIED HERE */
#endif
/* ... */
done:
if (init_ctype_locale != NULL) {
setlocale(LC_CTYPE, init_ctype_locale);
PyMem_RawFree(init_ctype_locale);
}
_PyPreConfig_Clear(&save_config);
Py_UTF8Mode = init_utf8_mode ; /* UNINITIALIZED READ HERE */
#ifdef MS_WINDOWS
Py_LegacyWindowsFSEncodingFlag = init_legacy_encoding; /* UNINITIALIZED READ HERE */
#endif
_PyPreCmdline_Clear(&cmdline);
return err;
}