mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-131998: Fix NULL
dereference when using an unbound method descriptor in a specialized code path (#132000)
Co-authored-by: sobolevn <mail@sobolevn.me> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Mark Shannon <mark@hotpy.org>
This commit is contained in:
parent
3eda146035
commit
ac3c439cdf
5 changed files with 47 additions and 0 deletions
|
@ -4300,12 +4300,14 @@ dummy_func(
|
|||
arguments--;
|
||||
total_args++;
|
||||
}
|
||||
EXIT_IF(total_args == 0);
|
||||
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
|
||||
EXIT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type));
|
||||
PyMethodDef *meth = method->d_method;
|
||||
EXIT_IF(meth->ml_flags != (METH_FASTCALL|METH_KEYWORDS));
|
||||
PyTypeObject *d_type = method->d_common.d_type;
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
|
||||
assert(self != NULL);
|
||||
EXIT_IF(!Py_IS_TYPE(self, d_type));
|
||||
STAT_INC(CALL, hit);
|
||||
int nargs = total_args - 1;
|
||||
|
@ -4378,12 +4380,14 @@ dummy_func(
|
|||
arguments--;
|
||||
total_args++;
|
||||
}
|
||||
EXIT_IF(total_args == 0);
|
||||
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
|
||||
/* Builtin METH_FASTCALL methods, without keywords */
|
||||
EXIT_IF(!Py_IS_TYPE(method, &PyMethodDescr_Type));
|
||||
PyMethodDef *meth = method->d_method;
|
||||
EXIT_IF(meth->ml_flags != METH_FASTCALL);
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
|
||||
assert(self != NULL);
|
||||
EXIT_IF(!Py_IS_TYPE(self, method->d_common.d_type));
|
||||
STAT_INC(CALL, hit);
|
||||
int nargs = total_args - 1;
|
||||
|
|
10
Python/executor_cases.c.h
generated
10
Python/executor_cases.c.h
generated
|
@ -5838,6 +5838,10 @@
|
|||
arguments--;
|
||||
total_args++;
|
||||
}
|
||||
if (total_args == 0) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
|
||||
if (!Py_IS_TYPE(method, &PyMethodDescr_Type)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
|
@ -5850,6 +5854,7 @@
|
|||
}
|
||||
PyTypeObject *d_type = method->d_common.d_type;
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
|
||||
assert(self != NULL);
|
||||
if (!Py_IS_TYPE(self, d_type)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
|
@ -5990,6 +5995,10 @@
|
|||
arguments--;
|
||||
total_args++;
|
||||
}
|
||||
if (total_args == 0) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
|
||||
if (!Py_IS_TYPE(method, &PyMethodDescr_Type)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
|
@ -6001,6 +6010,7 @@
|
|||
JUMP_TO_JUMP_TARGET();
|
||||
}
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
|
||||
assert(self != NULL);
|
||||
if (!Py_IS_TYPE(self, method->d_common.d_type)) {
|
||||
UOP_STAT_INC(uopcode, miss);
|
||||
JUMP_TO_JUMP_TARGET();
|
||||
|
|
12
Python/generated_cases.c.h
generated
12
Python/generated_cases.c.h
generated
|
@ -3333,6 +3333,11 @@
|
|||
arguments--;
|
||||
total_args++;
|
||||
}
|
||||
if (total_args == 0) {
|
||||
UPDATE_MISS_STATS(CALL);
|
||||
assert(_PyOpcode_Deopt[opcode] == (CALL));
|
||||
JUMP_TO_PREDICTED(CALL);
|
||||
}
|
||||
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
|
||||
if (!Py_IS_TYPE(method, &PyMethodDescr_Type)) {
|
||||
UPDATE_MISS_STATS(CALL);
|
||||
|
@ -3346,6 +3351,7 @@
|
|||
JUMP_TO_PREDICTED(CALL);
|
||||
}
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
|
||||
assert(self != NULL);
|
||||
if (!Py_IS_TYPE(self, method->d_common.d_type)) {
|
||||
UPDATE_MISS_STATS(CALL);
|
||||
assert(_PyOpcode_Deopt[opcode] == (CALL));
|
||||
|
@ -3453,6 +3459,11 @@
|
|||
arguments--;
|
||||
total_args++;
|
||||
}
|
||||
if (total_args == 0) {
|
||||
UPDATE_MISS_STATS(CALL);
|
||||
assert(_PyOpcode_Deopt[opcode] == (CALL));
|
||||
JUMP_TO_PREDICTED(CALL);
|
||||
}
|
||||
PyMethodDescrObject *method = (PyMethodDescrObject *)callable_o;
|
||||
if (!Py_IS_TYPE(method, &PyMethodDescr_Type)) {
|
||||
UPDATE_MISS_STATS(CALL);
|
||||
|
@ -3467,6 +3478,7 @@
|
|||
}
|
||||
PyTypeObject *d_type = method->d_common.d_type;
|
||||
PyObject *self = PyStackRef_AsPyObjectBorrow(arguments[0]);
|
||||
assert(self != NULL);
|
||||
if (!Py_IS_TYPE(self, d_type)) {
|
||||
UPDATE_MISS_STATS(CALL);
|
||||
assert(_PyOpcode_Deopt[opcode] == (CALL));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue