diff options
| author | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-19 10:41:45 (GMT) |
|---|---|---|
| committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-19 10:41:45 (GMT) |
| commit | 9101e23ff6006d9ede7d46e8c9e7d39e23c2a3c3 (patch) | |
| tree | c61aebdba4dddc8f10c9460ca33b0fa3f2e1495d /Modules/selectmodule.c | |
| parent | bd8f29028eab752e8e5c73703218a701028c1a9a (diff) | |
| parent | 441d30fac7f4037e4a79e4ada873de3b6f6e5a26 (diff) | |
| download | cpython-9101e23ff6006d9ede7d46e8c9e7d39e23c2a3c3.zip cpython-9101e23ff6006d9ede7d46e8c9e7d39e23c2a3c3.tar.gz cpython-9101e23ff6006d9ede7d46e8c9e7d39e23c2a3c3.tar.bz2 | |
Issue #15989: Fix several occurrences of integer overflow
when result of PyLong_AsLong() narrowed to int without checks.
This is a backport of changesets 13e2e44db99d and 525407d89277.
Diffstat (limited to 'Modules/selectmodule.c')
| -rw-r--r-- | Modules/selectmodule.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 9e53773..ce5ed47 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -357,10 +357,13 @@ update_ufd_array(pollObject *self) i = pos = 0; while (PyDict_Next(self->dict, &pos, &key, &value)) { - self->ufds[i].fd = PyLong_AsLong(key); + assert(i < self->ufd_len); + /* Never overflow */ + self->ufds[i].fd = (int)PyLong_AsLong(key); self->ufds[i].events = (short)PyLong_AsLong(value); i++; } + assert(i == self->ufd_len); self->ufd_uptodate = 1; return 1; } @@ -376,10 +379,11 @@ static PyObject * poll_register(pollObject *self, PyObject *args) { PyObject *o, *key, *value; - int fd, events = POLLIN | POLLPRI | POLLOUT; + int fd; + short events = POLLIN | POLLPRI | POLLOUT; int err; - if (!PyArg_ParseTuple(args, "O|i:register", &o, &events)) { + if (!PyArg_ParseTuple(args, "O|h:register", &o, &events)) { return NULL; } @@ -518,7 +522,7 @@ poll_poll(pollObject *self, PyObject *args) tout = PyNumber_Long(tout); if (!tout) return NULL; - timeout = PyLong_AsLong(tout); + timeout = _PyLong_AsInt(tout); Py_DECREF(tout); if (timeout == -1 && PyErr_Occurred()) return NULL; |
