diff options
author | Stefan Krah <skrah@bytereef.org> | 2017-09-10 16:08:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-10 16:08:04 (GMT) |
commit | 3cedf46cdbeefc019f4a672c1104f3d5e94712bd (patch) | |
tree | acf10fd41f7bd8a595c32817baafb3d6aa489bac /Modules | |
parent | 30644dee0c14af6c1c61d44166a97cec8245300b (diff) | |
download | cpython-3cedf46cdbeefc019f4a672c1104f3d5e94712bd.zip cpython-3cedf46cdbeefc019f4a672c1104f3d5e94712bd.tar.gz cpython-3cedf46cdbeefc019f4a672c1104f3d5e94712bd.tar.bz2 |
bpo-31406: Fix crash due to lack of type checking in subclassing. (#3477)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_decimal/_decimal.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index e3c1a79..18fa2e4 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -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; } @@ -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; } |