diff options
| author | Mark Dickinson <mdickinson@enthought.com> | 2012-10-06 18:04:49 +0100 |
|---|---|---|
| committer | Mark Dickinson <mdickinson@enthought.com> | 2012-10-06 18:04:49 +0100 |
| commit | c04ddff290fc203d05b75c8569b748525fb76b5b (patch) | |
| tree | 184849e76ebe965016c2737939f9eaa0dfb900ee /Modules/_datetimemodule.c | |
| parent | a2028733ef072740921017e544d29d191fdb2c9c (diff) | |
| download | cpython-git-c04ddff290fc203d05b75c8569b748525fb76b5b.tar.gz | |
Issue #16096: Fix several occurrences of potential signed integer overflow. Thanks Serhiy Storchaka.
Diffstat (limited to 'Modules/_datetimemodule.c')
| -rw-r--r-- | Modules/_datetimemodule.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 01c85d1cd3..873d46fd1b 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1265,14 +1265,13 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, assert(ptoappend != NULL); assert(ntoappend > 0); while (usednew + ntoappend > totalnew) { - size_t bigger = totalnew << 1; - if ((bigger >> 1) != totalnew) { /* overflow */ + if (totalnew > (PY_SSIZE_T_MAX >> 1)) { /* overflow */ PyErr_NoMemory(); goto Done; } - if (_PyBytes_Resize(&newfmt, bigger) < 0) + totalnew <<= 1; + if (_PyBytes_Resize(&newfmt, totalnew) < 0) goto Done; - totalnew = bigger; pnew = PyBytes_AsString(newfmt) + usednew; } memcpy(pnew, ptoappend, ntoappend); |
