summaryrefslogtreecommitdiff
path: root/Modules/_struct.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-02-14 11:26:18 +0000
committerMartin v. Löwis <martin@v.loewis.de>2008-02-14 11:26:18 +0000
commit27701ea6d05319c634182880325e6ae0d3f977d0 (patch)
treeabcbb14f1949188a0062ba9497220ff25798ea19 /Modules/_struct.c
parentf341b896b0a79a061ad2cca4eab818d6dee03d92 (diff)
downloadcpython-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.c6
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));