summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-03-19 19:04:25 (GMT)
committerGuido van Rossum <guido@python.org>1999-03-19 19:04:25 (GMT)
commit49ded3ec004c49088ec26c808f9b7c931a35cf0f (patch)
tree3dec11ca46f049474c8ee3ae6ae1f98e9bf2c097
parent7d5f5dd6aa203e6fe56ec6a35087b64a1a845ae6 (diff)
downloadcpython-49ded3ec004c49088ec26c808f9b7c931a35cf0f.zip
cpython-49ded3ec004c49088ec26c808f9b7c931a35cf0f.tar.gz
cpython-49ded3ec004c49088ec26c808f9b7c931a35cf0f.tar.bz2
Added check for negative offset for PyBuffer_FromObject and check for
negative size for PyBuffer_FromMemory. Greg Stein.
-rw-r--r--Objects/bufferobject.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Objects/bufferobject.c b/Objects/bufferobject.c
index 091688d..86d0487 100644
--- a/Objects/bufferobject.c
+++ b/Objects/bufferobject.c
@@ -55,6 +55,12 @@ _PyBuffer_FromMemory(base, ptr, size, readonly)
{
PyBufferObject * b;
+ if ( size < 0 ) {
+ PyErr_SetString(PyExc_ValueError,
+ "size must be zero or positive");
+ return NULL;
+ }
+
b = PyObject_NEW(PyBufferObject, &PyBuffer_Type);
if ( b == NULL )
return NULL;
@@ -83,6 +89,12 @@ _PyBuffer_FromObject(base, offset, size, proc, readonly)
void *p;
int count;
+ if ( offset < 0 ) {
+ PyErr_SetString(PyExc_ValueError,
+ "offset must be zero or positive");
+ return NULL;
+ }
+
if ( (*pb->bf_getsegcount)(base, NULL) != 1 )
{
PyErr_SetString(PyExc_TypeError, "single-segment buffer object expected");
@@ -92,7 +104,7 @@ _PyBuffer_FromObject(base, offset, size, proc, readonly)
return NULL;
/* apply constraints to the start/end */
- if ( size == Py_END_OF_BUFFER )
+ if ( size == Py_END_OF_BUFFER || size < 0 )
size = count;
if ( offset > count )
offset = count;