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.
This commit is contained in:
Serhiy Storchaka 2013-01-19 12:55:39 +02:00
parent ac7b49f407
commit 74f49ab28b
17 changed files with 143 additions and 22 deletions

View file

@ -2659,10 +2659,10 @@ int PyObject_AsFileDescriptor(PyObject *o)
PyObject *meth;
if (PyInt_Check(o)) {
fd = PyInt_AsLong(o);
fd = _PyInt_AsInt(o);
}
else if (PyLong_Check(o)) {
fd = PyLong_AsLong(o);
fd = _PyLong_AsInt(o);
}
else if ((meth = PyObject_GetAttrString(o, "fileno")) != NULL)
{
@ -2672,11 +2672,11 @@ int PyObject_AsFileDescriptor(PyObject *o)
return -1;
if (PyInt_Check(fno)) {
fd = PyInt_AsLong(fno);
fd = _PyInt_AsInt(fno);
Py_DECREF(fno);
}
else if (PyLong_Check(fno)) {
fd = PyLong_AsLong(fno);
fd = _PyLong_AsInt(fno);
Py_DECREF(fno);
}
else {