mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
GH-96569: Add two NULL checks to avoid undefined behavior. (GH-96585)
This commit is contained in:
parent
cd0ff9bd14
commit
222f10ca2d
3 changed files with 13 additions and 10 deletions
|
@ -190,11 +190,16 @@ _PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame);
|
||||||
void
|
void
|
||||||
_PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear);
|
_PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear);
|
||||||
|
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
_PyThreadState_HasStackSpace(PyThreadState *tstate, int size)
|
_PyThreadState_HasStackSpace(PyThreadState *tstate, int size)
|
||||||
{
|
{
|
||||||
return tstate->datastack_top + size < tstate->datastack_limit;
|
assert(
|
||||||
|
(tstate->datastack_top == NULL && tstate->datastack_limit == NULL)
|
||||||
|
||
|
||||||
|
(tstate->datastack_top != NULL && tstate->datastack_limit != NULL)
|
||||||
|
);
|
||||||
|
return tstate->datastack_top != NULL &&
|
||||||
|
size < tstate->datastack_limit - tstate->datastack_top;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern _PyInterpreterFrame *
|
extern _PyInterpreterFrame *
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Remove two cases of undefined behavoir, by adding NULL checks.
|
|
@ -2195,15 +2195,12 @@ _PyInterpreterFrame *
|
||||||
_PyThreadState_PushFrame(PyThreadState *tstate, size_t size)
|
_PyThreadState_PushFrame(PyThreadState *tstate, size_t size)
|
||||||
{
|
{
|
||||||
assert(size < INT_MAX/sizeof(PyObject *));
|
assert(size < INT_MAX/sizeof(PyObject *));
|
||||||
PyObject **base = tstate->datastack_top;
|
if (_PyThreadState_HasStackSpace(tstate, (int)size)) {
|
||||||
PyObject **top = base + size;
|
_PyInterpreterFrame *res = (_PyInterpreterFrame *)tstate->datastack_top;
|
||||||
if (top >= tstate->datastack_limit) {
|
tstate->datastack_top += size;
|
||||||
base = push_chunk(tstate, (int)size);
|
return res;
|
||||||
}
|
}
|
||||||
else {
|
return (_PyInterpreterFrame *)push_chunk(tstate, (int)size);
|
||||||
tstate->datastack_top = top;
|
|
||||||
}
|
|
||||||
return (_PyInterpreterFrame *)base;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue