This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Need a look for return value checking [selectmodule.c]
Type: crash Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alexc, xiang.zhang
Priority: normal Keywords:

Created on 2017-03-22 04:14 by alexc, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 758 merged xiang.zhang, 2017-03-22 04:30
Messages (3)
msg289967 - (view) Author: Alex CHEN (alexc) Date: 2017-03-22 04:14
In file selectmodule.c

our static code scanner has reported the following case, function set2list is liable to return NULL (if PyTuple_New failed),  would any chance the NULL pointer be dereferenced (Py_DECREF(fdlist) after set2list) or it would just raise python exception to handle PyTuple_New error ?

static PyObject *
select_select(PyObject *self, PyObject *args)
{
    ......
    if (n < 0) {
        PyErr_SetFromErrno(SelectError);
    }
#endif
    else {
        /* any of these three calls can raise an exception.  it's more
           convenient to test for this after all three calls... but
           is that acceptable?
        */
        ifdlist = set2list(&ifdset, rfd2obj);          //   || <=====
        ofdlist = set2list(&ofdset, wfd2obj);          //   ||
        efdlist = set2list(&efdset, efd2obj);          //   ||
        if (PyErr_Occurred())
            ret = NULL;
        else
            ret = PyTuple_Pack(3, ifdlist, ofdlist, efdlist);

        Py_DECREF(ifdlist);
        Py_DECREF(ofdlist);
        Py_DECREF(efdlist);
msg289968 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-03-22 04:25
This has been fixed for 3.x in #18408 but not backported to 2.7.
msg290116 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-03-24 20:09
New changeset e6a55dd8391651a7d3a97b6215e70e48e628d3d7 by Xiang Zhang in branch '2.7':
bpo-29874: fix INCREF for possible NULL values in select_select() (GH-758)
https://github.com/python/cpython/commit/e6a55dd8391651a7d3a97b6215e70e48e628d3d7
History
Date User Action Args
2022-04-11 14:58:44adminsetgithub: 74060
2017-03-24 20:09:15xiang.zhangsetmessages: + msg290116
2017-03-22 04:46:36xiang.zhangsetstatus: open -> closed
resolution: fixed
stage: resolved
2017-03-22 04:30:54xiang.zhangsetpull_requests: + pull_request672
2017-03-22 04:25:10xiang.zhangsetnosy: + xiang.zhang
messages: + msg289968
2017-03-22 04:22:41xiang.zhangsetversions: + Python 2.7
2017-03-22 04:14:52alexcsettype: crash
2017-03-22 04:14:16alexccreate