diff options
| author | Gregory P. Smith <greg@mad-scientist.com> | 2008-06-11 07:41:16 (GMT) |
|---|---|---|
| committer | Gregory P. Smith <greg@mad-scientist.com> | 2008-06-11 07:41:16 (GMT) |
| commit | 9d53457e599623fbad90833c3448835b42d7e7f9 (patch) | |
| tree | 41d37b556618eb8e831463c576d854063a33d77b /Modules/cStringIO.c | |
| parent | 73baefd7fc86a7f8336e4142efcec74c201acf8f (diff) | |
| download | cpython-9d53457e599623fbad90833c3448835b42d7e7f9.zip cpython-9d53457e599623fbad90833c3448835b42d7e7f9.tar.gz cpython-9d53457e599623fbad90833c3448835b42d7e7f9.tar.bz2 | |
Merge in release25-maint r60793:
Added checks for integer overflows, contributed by Google. Some are
only available if asserts are left in the code, in cases where they
can't be triggered from Python code.
Diffstat (limited to 'Modules/cStringIO.c')
| -rw-r--r-- | Modules/cStringIO.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c index 139a4a8..237d8c2 100644 --- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -119,6 +119,7 @@ PyDoc_STRVAR(IO_getval__doc__, static PyObject * IO_cgetval(PyObject *self) { if (!IO__opencheck(IOOOBJECT(self))) return NULL; + assert(IOOOBJECT(self)->pos >= 0); return PyString_FromStringAndSize(((IOobject*)self)->buf, ((IOobject*)self)->pos); } @@ -137,6 +138,7 @@ IO_getval(IOobject *self, PyObject *args) { } else s=self->string_size; + assert(self->pos >= 0); return PyString_FromStringAndSize(self->buf, s); } @@ -157,6 +159,8 @@ IO_cread(PyObject *self, char **output, Py_ssize_t n) { Py_ssize_t l; if (!IO__opencheck(IOOOBJECT(self))) return -1; + assert(IOOOBJECT(self)->pos >= 0); + assert(IOOOBJECT(self)->string_size >= 0); l = ((IOobject*)self)->string_size - ((IOobject*)self)->pos; if (n < 0 || n > l) { n = l; @@ -192,12 +196,17 @@ IO_creadline(PyObject *self, char **output) { for (n = ((IOobject*)self)->buf + ((IOobject*)self)->pos, s = ((IOobject*)self)->buf + ((IOobject*)self)->string_size; n < s && *n != '\n'; n++); + if (n < s) n++; *output=((IOobject*)self)->buf + ((IOobject*)self)->pos; l = n - ((IOobject*)self)->buf - ((IOobject*)self)->pos; - assert(((IOobject*)self)->pos + l < INT_MAX); - ((IOobject*)self)->pos += (int)l; + + assert(IOOOBJECT(self)->pos <= PY_SSIZE_T_MAX - l); + assert(IOOOBJECT(self)->pos >= 0); + assert(IOOOBJECT(self)->string_size >= 0); + + ((IOobject*)self)->pos += l; return (int)l; } @@ -215,6 +224,7 @@ IO_readline(IOobject *self, PyObject *args) { n -= m; self->pos -= m; } + assert(IOOOBJECT(self)->pos >= 0); return PyString_FromStringAndSize(output, n); } @@ -277,6 +287,7 @@ IO_tell(IOobject *self, PyObject *unused) { if (!IO__opencheck(self)) return NULL; + assert(self->pos >= 0); return PyInt_FromSsize_t(self->pos); } |
