summaryrefslogtreecommitdiffstats
path: root/Modules/pyexpat.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-09-07 19:54:08 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-09-07 19:54:08 (GMT)
commit6c8b66cd261c6418566700527784b17bb459db1f (patch)
tree3df00565bbfc1a2ca40ae66cb6a357efc6e9c922 /Modules/pyexpat.c
parent3b1bc7828dff9c58031f60f9d603ca78cbba96ea (diff)
parentde5f9f4f70c6527c49d482e3b0bb0aad2851d34c (diff)
downloadcpython-6c8b66cd261c6418566700527784b17bb459db1f.zip
cpython-6c8b66cd261c6418566700527784b17bb459db1f.tar.gz
cpython-6c8b66cd261c6418566700527784b17bb459db1f.tar.bz2
Raise more correct exception on overflow in setting buffer_size attribute of
expat parser.
Diffstat (limited to 'Modules/pyexpat.c')
-rw-r--r--Modules/pyexpat.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 60f6443..9a6da73 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1440,17 +1440,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];