summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-05-30 14:45:22 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-05-30 14:45:22 (GMT)
commitfa494fd88384acc52cf9292d0c89e2961c8f747f (patch)
treea30958b83189caf872f34e7b94a1aeeef28ed3a9 /Modules
parent50451eb91232b0e90c677419db19ed7b33a698a9 (diff)
downloadcpython-fa494fd88384acc52cf9292d0c89e2961c8f747f.zip
cpython-fa494fd88384acc52cf9292d0c89e2961c8f747f.tar.gz
cpython-fa494fd88384acc52cf9292d0c89e2961c8f747f.tar.bz2
Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains() to check for and handle errors correctly.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_json.c24
-rw-r--r--Modules/_threadmodule.c18
-rw-r--r--Modules/faulthandler.c4
3 files changed, 31 insertions, 15 deletions
diff --git a/Modules/_json.c b/Modules/_json.c
index f87d680..2f42c34 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -595,6 +595,9 @@ _parse_object_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ss
int has_pairs_hook = (s->object_pairs_hook != Py_None);
Py_ssize_t next_idx;
+ if (strict < 0)
+ return NULL;
+
if (PyUnicode_READY(pystr) == -1)
return NULL;
@@ -940,6 +943,7 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
void *str;
int kind;
Py_ssize_t length;
+ int strict;
if (PyUnicode_READY(pystr) == -1)
return NULL;
@@ -960,9 +964,10 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
switch (PyUnicode_READ(kind, str, idx)) {
case '"':
/* string */
- return scanstring_unicode(pystr, idx + 1,
- PyObject_IsTrue(s->strict),
- next_idx_ptr);
+ strict = PyObject_IsTrue(s->strict);
+ if (strict < 0)
+ return NULL;
+ return scanstring_unicode(pystr, idx + 1, strict, next_idx_ptr);
case '{':
/* object */
if (Py_EnterRecursiveCall(" while decoding a JSON object "
@@ -1212,12 +1217,13 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
PyEncoderObject *s;
PyObject *markers, *defaultfn, *encoder, *indent, *key_separator;
- PyObject *item_separator, *sort_keys, *skipkeys, *allow_nan;
+ PyObject *item_separator, *sort_keys, *skipkeys;
+ int allow_nan;
assert(PyEncoder_Check(self));
s = (PyEncoderObject *)self;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOOOOOO:make_encoder", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOOOOOp:make_encoder", kwlist,
&markers, &defaultfn, &encoder, &indent, &key_separator, &item_separator,
&sort_keys, &skipkeys, &allow_nan))
return -1;
@@ -1231,7 +1237,7 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
s->sort_keys = sort_keys;
s->skipkeys = skipkeys;
s->fast_encode = (PyCFunction_Check(s->encoder) && PyCFunction_GetFunction(s->encoder) == (PyCFunction)py_encode_basestring_ascii);
- s->allow_nan = PyObject_IsTrue(allow_nan);
+ s->allow_nan = allow_nan;
Py_INCREF(s->markers);
Py_INCREF(s->defaultfn);
@@ -1500,6 +1506,7 @@ encoder_listencode_dict(PyEncoderObject *s, _PyAccu *acc,
PyObject *items;
PyObject *item = NULL;
int skipkeys;
+ int sortkeys;
Py_ssize_t idx;
if (open_dict == NULL || close_dict == NULL || empty_dict == NULL) {
@@ -1544,13 +1551,16 @@ encoder_listencode_dict(PyEncoderObject *s, _PyAccu *acc,
items = PyMapping_Items(dct);
if (items == NULL)
goto bail;
- if (PyObject_IsTrue(s->sort_keys) && PyList_Sort(items) < 0)
+ sortkeys = PyObject_IsTrue(s->sort_keys);
+ if (sortkeys < 0 || (sortkeys && PyList_Sort(items) < 0))
goto bail;
it = PyObject_GetIter(items);
Py_DECREF(items);
if (it == NULL)
goto bail;
skipkeys = PyObject_IsTrue(s->skipkeys);
+ if (skipkeys < 0)
+ goto bail;
idx = 0;
while ((item = PyIter_Next(it)) != NULL) {
PyObject *encoded, *key, *value;
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 9925b0e..f80f76a 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -718,12 +718,18 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
"_localdummy_destroyed", (PyCFunction) _localdummy_destroyed, METH_O
};
- if (type->tp_init == PyBaseObject_Type.tp_init
- && ((args && PyObject_IsTrue(args))
- || (kw && PyObject_IsTrue(kw)))) {
- PyErr_SetString(PyExc_TypeError,
- "Initialization arguments are not supported");
- return NULL;
+ if (type->tp_init == PyBaseObject_Type.tp_init) {
+ int rc = 0;
+ if (args != NULL)
+ rc = PyObject_IsTrue(args);
+ if (rc == 0 && kw != NULL)
+ rc = PyObject_IsTrue(kw);
+ if (rc != 0) {
+ if (rc > 0)
+ PyErr_SetString(PyExc_TypeError,
+ "Initialization arguments are not supported");
+ return NULL;
+ }
}
self = (localobject *)type->tp_alloc(type, 0);
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index c729414..1493f8d 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -1087,8 +1087,8 @@ faulthandler_env_options(void)
has_key = PyDict_Contains(xoptions, key);
Py_DECREF(key);
- if (!has_key)
- return 0;
+ if (has_key <= 0)
+ return has_key;
}
module = PyImport_ImportModule("faulthandler");