classification
Title: Local variables can be used uninitialized in _PyPreConfig_Read()
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: blarsen, vstinner
Priority: normal Keywords: patch

Created on 2019-03-31 16:46 by blarsen, last changed 2019-04-05 09:46 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12644 closed blarsen, 2019-03-31 17:03
Messages (3)
msg339268 - (view) Author: Brad Larsen (blarsen) * Date: 2019-03-31 16:46
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;
    }
msg339484 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-04-05 09:45
Fixed by commit 6a8c3139ae9ada89d4a95985ec7cf8bb7d03bc01.
msg339485 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-04-05 09:46
Thanks for your bug report and fix Brad Larsen ;-)
History
Date User Action Args
2019-04-05 09:46:15vstinnersetmessages: + msg339485
2019-04-05 09:45:58vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg339484

stage: patch review -> resolved
2019-03-31 17:03:30xtreaksetnosy: + vstinner
2019-03-31 17:03:06blarsensetkeywords: + patch
stage: patch review
pull_requests: + pull_request12576
2019-03-31 16:46:03blarsencreate