Issue 4460: The parameter of PyInt_AsSsize_t() is not checked to see if it is NULL (original) (raw)

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:41 admin set github: 48710
2008-11-29 17:43:51 mark.dickinson set status: open -> closedresolution: not a bugmessages: +
2008-11-29 17:34:47 CWRU_Researcher1 set messages: +
2008-11-29 17:17:20 mark.dickinson set nosy: + mark.dickinsonmessages: +
2008-11-29 16:35:42 CWRU_Researcher1 create