diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2008-02-14 11:26:18 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2008-02-14 11:26:18 +0000 |
commit | 27701ea6d05319c634182880325e6ae0d3f977d0 (patch) | |
tree | abcbb14f1949188a0062ba9497220ff25798ea19 /Modules/_struct.c | |
parent | f341b896b0a79a061ad2cca4eab818d6dee03d92 (diff) | |
download | cpython-27701ea6d05319c634182880325e6ae0d3f977d0.tar.gz |
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/_struct.c')
-rw-r--r-- | Modules/_struct.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c index 53c64848b1..41183fa26b 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1336,6 +1336,12 @@ prepare_s(PyStructObject *self) } } + /* check for overflow */ + if ((len + 1) > (PY_SSIZE_T_MAX / sizeof(formatcode))) { + PyErr_NoMemory(); + return -1; + } + self->s_size = size; self->s_len = len; codes = PyMem_MALLOC((len + 1) * sizeof(formatcode)); |