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
commit73c01d410117a573731e6c2afc9694005f8d11aa (patch)
treec0cb9e868b2cb57d9ebd5685d0054b551a33e889 /Modules/_struct.c
parentabcb59a1d87c6121db913ce56c9f91fd43f33916 (diff)
downloadcpython-git-73c01d410117a573731e6c2afc9694005f8d11aa.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));