summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-09-07 19:51:56 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-09-07 19:51:56 (GMT)
commitde5f9f4f70c6527c49d482e3b0bb0aad2851d34c (patch)
treec93349effc14d46a0b617dd59c01c32337dd29f6 /Modules
parent931331a328d522bb014f9e9c13884d7566108268 (diff)
downloadcpython-de5f9f4f70c6527c49d482e3b0bb0aad2851d34c.zip
cpython-de5f9f4f70c6527c49d482e3b0bb0aad2851d34c.tar.gz
cpython-de5f9f4f70c6527c49d482e3b0bb0aad2851d34c.tar.bz2
Raise more correct exception on overflow in setting buffer_size attribute of
expat parser.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/pyexpat.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index c4fdaaf..6a901f7 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1403,17 +1403,18 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v)
return -1;
}
- new_buffer_size=PyLong_AS_LONG(v);
+ new_buffer_size = PyLong_AsLong(v);
+ if (new_buffer_size <= 0) {
+ if (!PyErr_Occurred())
+ PyErr_SetString(PyExc_ValueError, "buffer_size must be greater than zero");
+ return -1;
+ }
+
/* trivial case -- no change */
if (new_buffer_size == self->buffer_size) {
return 0;
}
- if (new_buffer_size <= 0) {
- PyErr_SetString(PyExc_ValueError, "buffer_size must be greater than zero");
- return -1;
- }
-
/* check maximum */
if (new_buffer_size > INT_MAX) {
char errmsg[100];