Skip to content

Commit

Permalink
bpo-31406: Fix crash due to lack of type checking in subclassing. (py…
Browse files Browse the repository at this point in the history
  • Loading branch information
skrah authored Sep 10, 2017
1 parent 30644de commit 3cedf46
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2082,13 +2082,17 @@ dec_from_long(PyTypeObject *type, const PyObject *v,
/* Return a new PyDecObject from a PyLongObject. Use the context for
conversion. */
static PyObject *
PyDecType_FromLong(PyTypeObject *type, const PyObject *pylong,
PyObject *context)
PyDecType_FromLong(PyTypeObject *type, const PyObject *v, PyObject *context)
{
PyObject *dec;
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) {
return NULL;
}
Expand All @@ -2104,15 +2108,20 @@ PyDecType_FromLong(PyTypeObject *type, const PyObject *pylong,
/* Return a new PyDecObject from a PyLongObject. Use a maximum context
for conversion. If the conversion is not exact, set InvalidOperation. */
static PyObject *
PyDecType_FromLongExact(PyTypeObject *type, const PyObject *pylong,
PyDecType_FromLongExact(PyTypeObject *type, const PyObject *v,
PyObject *context)
{
PyObject *dec;
uint32_t status = 0;
mpd_context_t maxctx;

if (!PyLong_Check(v)) {
PyErr_SetString(PyExc_TypeError, "argument must be an integer");
return NULL;
}

mpd_maxcontext(&maxctx);
dec = dec_from_long(type, pylong, &maxctx, &status);
dec = dec_from_long(type, v, &maxctx, &status);
if (dec == NULL) {
return NULL;
}
Expand Down

0 comments on commit 3cedf46

Please sign in to comment.