mirror of
https://github.com/python/cpython.git
synced 2025-09-29 19:56:59 +00:00
[3.6] bpo-31406: Fix crash due to lack of type checking in subclassing. (GH-3477) (#3479)
(cherry picked from commit 3cedf46cdb
)
This commit is contained in:
parent
638601ec52
commit
f8909d0e4b
1 changed files with 14 additions and 5 deletions
|
@ -2163,13 +2163,17 @@ dec_from_long(PyTypeObject *type, const PyObject *v,
|
||||||
/* Return a new PyDecObject from a PyLongObject. Use the context for
|
/* Return a new PyDecObject from a PyLongObject. Use the context for
|
||||||
conversion. */
|
conversion. */
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PyDecType_FromLong(PyTypeObject *type, const PyObject *pylong,
|
PyDecType_FromLong(PyTypeObject *type, const PyObject *v, PyObject *context)
|
||||||
PyObject *context)
|
|
||||||
{
|
{
|
||||||
PyObject *dec;
|
PyObject *dec;
|
||||||
uint32_t status = 0;
|
uint32_t status = 0;
|
||||||
|
|
||||||
dec = dec_from_long(type, pylong, CTX(context), &status);
|
if (!PyLong_Check(v)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "argument must be an integer");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
dec = dec_from_long(type, v, CTX(context), &status);
|
||||||
if (dec == NULL) {
|
if (dec == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2185,15 +2189,20 @@ PyDecType_FromLong(PyTypeObject *type, const PyObject *pylong,
|
||||||
/* Return a new PyDecObject from a PyLongObject. Use a maximum context
|
/* Return a new PyDecObject from a PyLongObject. Use a maximum context
|
||||||
for conversion. If the conversion is not exact, set InvalidOperation. */
|
for conversion. If the conversion is not exact, set InvalidOperation. */
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PyDecType_FromLongExact(PyTypeObject *type, const PyObject *pylong,
|
PyDecType_FromLongExact(PyTypeObject *type, const PyObject *v,
|
||||||
PyObject *context)
|
PyObject *context)
|
||||||
{
|
{
|
||||||
PyObject *dec;
|
PyObject *dec;
|
||||||
uint32_t status = 0;
|
uint32_t status = 0;
|
||||||
mpd_context_t maxctx;
|
mpd_context_t maxctx;
|
||||||
|
|
||||||
|
if (!PyLong_Check(v)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "argument must be an integer");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
mpd_maxcontext(&maxctx);
|
mpd_maxcontext(&maxctx);
|
||||||
dec = dec_from_long(type, pylong, &maxctx, &status);
|
dec = dec_from_long(type, v, &maxctx, &status);
|
||||||
if (dec == NULL) {
|
if (dec == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue