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: The parameter of PyInt_AsSsize_t() is not checked to see if it is NULL
Type: resource usage Stage:
Components: None Versions: Python 2.5.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: CWRU_Researcher1, mark.dickinson
Priority: normal Keywords:

Created on 2008-11-29 16:35 by CWRU_Researcher1, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg76600 - (view) Author: Brian Szuter (CWRU_Researcher1) Date: 2008-11-29 16:35
Python-2.5.2/Modules/_sre.c(match_getindex)
Line 2766

The parameter of PyInt_AsSsize_t() is not checked to see if it is NULL.
msg76607 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2008-11-29 17:17
I'm confused.  I'm probably missing something, but why do you think such a 
check is necessary?  The code I'm seeing at around line 2766 is:

static Py_ssize_t
match_getindex(MatchObject* self, PyObject* index)
{
    Py_ssize_t i;

    if (PyInt_Check(index))
        return PyInt_AsSsize_t(index);

...

Is there any reason to expect that the index argument to match_getindex 
might be NULL?  Even if it were, surely it would be the PyInt_Check call 
that would be affected, not PyInt_AsSsize_t?

The usual pattern in Python C code is to check return values, but not 
incoming arguments.
msg76609 - (view) Author: Brian Szuter (CWRU_Researcher1) Date: 2008-11-29 17:34
abstract.c(PyNumber_AsSsize_t) shows this check of PyInt_AsSsize_t()'s
parameter:

980: 	if (value == NULL)    
981: 		return -1;    
982:     
983: 	/* We're done if PyInt_AsSsize_t() returns without error. */   
984: 	result = PyInt_AsSsize_t(value);

Similar checks of this parameter occur in the following places:
classobject.c(instance_length) 980
sliceobject.c(PySlice_GetIndices) 1020
sliceobject.c(PySlice_GetIndices) 123
sliceobject.c(PySlice_GetIndices) 115
ceval.c(PyEval_EvalFrameEx) 1179
_sre.c(match_getindex) 2772
msg76612 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2008-11-29 17:43
> abstract.c(PyNumber_AsSsize_t) shows this check of PyInt_AsSsize_t()'s
> parameter:

Yup.  And that's because 'value' is the return value from 
PyNumber_Index.  PyNumber_Index might return NULL, so the check is 
necessary.

Am closing this as invalid.

I appreciate that you're trying to help here;  may I suggest that you 
take some time to read through the various development docs available?
History
Date User Action Args
2022-04-11 14:56:41adminsetgithub: 48710
2008-11-29 17:43:51mark.dickinsonsetstatus: open -> closed
resolution: not a bug
messages: + msg76612
2008-11-29 17:34:47CWRU_Researcher1setmessages: + msg76609
2008-11-29 17:17:20mark.dickinsonsetnosy: + mark.dickinson
messages: + msg76607
2008-11-29 16:35:42CWRU_Researcher1create