[Python-checkins] [3.6] bpo-31406: Fix crash due to lack of type checking in subclassing. (GH-3477) (#3479)
Stefan Krah
webhook-mailer at python.org
Sun Sep 10 12:46:52 EDT 2017
https://github.com/python/cpython/commit/f8909d0e4b652256e4da153fa6be664490f60a07
commit: f8909d0e4b652256e4da153fa6be664490f60a07
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Stefan Krah <skrah at bytereef.org>
date: 2017-09-10T18:46:49+02:00
summary:
[3.6] bpo-31406: Fix crash due to lack of type checking in subclassing. (GH-3477) (#3479)
(cherry picked from commit 3cedf46cdbeefc019f4a672c1104f3d5e94712bd)
files:
M Modules/_decimal/_decimal.c
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index fcc1f151cf5..13418c905b2 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -2163,13 +2163,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;
}
@@ -2185,15 +2189,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;
}
More information about the Python-checkins
mailing list