[issue13083] _sre: getstring() releases the buffer before using it

STINNER Victor report at bugs.python.org
Sat Oct 1 03:50:51 CEST 2011


New submission from STINNER Victor <victor.stinner at haypocalc.com>:

getstring() of the _sre module contains the following code:
-------------
    ...
    buffer = Py_TYPE(string)->tp_as_buffer;
    if (!buffer || !buffer->bf_getbuffer ||
        (*buffer->bf_getbuffer)(string, &view, PyBUF_SIMPLE) < 0) {
            PyErr_SetString(PyExc_TypeError, "expected string or buffer");
            return NULL;
    }

    /* determine buffer size */
    bytes = view.len;
    ptr = view.buf;

    /* Release the buffer immediately --- possibly dangerous
       but doing something else would require some re-factoring
    */
    PyBuffer_Release(&view);
    ...
-------------

getstring() is used to initialize a state or a pattern. State and pattern have destructors (pattern_dealloc() and state_fini()), so it should be possible to keep the view active and call PyBuffer_Release() in the destructor.

----------
components: Library (Lib)
messages: 144714
nosy: haypo, pitrou
priority: normal
severity: normal
status: open
title: _sre: getstring() releases the buffer before using it
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13083>
_______________________________________


More information about the Python-bugs-list mailing list