summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorStefan Krah <skrah@bytereef.org>2012-08-23 13:53:45 (GMT)
committerStefan Krah <skrah@bytereef.org>2012-08-23 13:53:45 (GMT)
commit66e63170d9aa8cf41a772b0d22b20c47636d24f5 (patch)
tree29b15f54cfe392bae18d1d7c4ec7a51457dcfe3a /Modules
parentf21587e3a805f8ced02dc65c54195bb26740a0ad (diff)
downloadcpython-66e63170d9aa8cf41a772b0d22b20c47636d24f5.zip
cpython-66e63170d9aa8cf41a772b0d22b20c47636d24f5.tar.gz
cpython-66e63170d9aa8cf41a772b0d22b20c47636d24f5.tar.bz2
Issue #15770: Check invalid arguments in test function. Patch by Victor Stinner.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testbuffer.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c
index b291a14..87ada0a 100644
--- a/Modules/_testbuffer.c
+++ b/Modules/_testbuffer.c
@@ -2362,6 +2362,13 @@ get_ascii_order(PyObject *order)
ord = PyBytes_AS_STRING(ascii_order)[0];
Py_DECREF(ascii_order);
+
+ if (ord != 'C' && ord != 'F' && ord != 'A') {
+ PyErr_SetString(PyExc_ValueError,
+ "invalid order, must be C, F or A");
+ return CHAR_MAX;
+ }
+
return ord;
}
@@ -2384,15 +2391,20 @@ get_contiguous(PyObject *self, PyObject *args)
"buffertype must be PyBUF_READ or PyBUF_WRITE");
return NULL;
}
+
type = PyLong_AsLong(buffertype);
if (type == -1 && PyErr_Occurred()) {
return NULL;
}
+ if (type != PyBUF_READ && type != PyBUF_WRITE) {
+ PyErr_SetString(PyExc_ValueError,
+ "invalid buffer type");
+ return NULL;
+ }
ord = get_ascii_order(order);
- if (ord == CHAR_MAX) {
+ if (ord == CHAR_MAX)
return NULL;
- }
return PyMemoryView_GetContiguous(obj, (int)type, ord);
}