diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-19 12:55:39 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-19 12:55:39 +0200 |
commit | 74f49ab28b91d3c23524356230feb2724ee9b23f (patch) | |
tree | 0ddd5e8899d06c974dfc25a7dfc298e3f6f70039 /Objects/intobject.c | |
parent | ac7b49f4076a4336915d13a4aa19feaeadd29d62 (diff) | |
download | cpython-git-74f49ab28b91d3c23524356230feb2724ee9b23f.tar.gz |
Issue #15989: Fix several occurrences of integer overflow
when result of PyInt_AsLong() or PyLong_AsLong() narrowed
to int without checks.
This is a backport of changesets 13e2e44db99d and 525407d89277.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r-- | Objects/intobject.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index 1ae8006c28..28182f93db 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -189,6 +189,20 @@ PyInt_AsLong(register PyObject *op) return val; } +int +_PyInt_AsInt(PyObject *obj) +{ + long result = PyInt_AsLong(obj); + if (result == -1 && PyErr_Occurred()) + return -1; + if (result > INT_MAX || result < INT_MIN) { + PyErr_SetString(PyExc_OverflowError, + "Python int too large to convert to C int"); + return -1; + } + return (int)result; +} + Py_ssize_t PyInt_AsSsize_t(register PyObject *op) { |