Mercurial > cpython-lru_cache-weakref
diff Modules/parsermodule.c @ 81505:13e2e44db99d
Issue #15989: Fix several occurrences of integer overflow
when result of PyLong_AsLong() narrowed to int without checks.
| author | Serhiy Storchaka <storchaka@gmail.com> |
|---|---|
| date | Tue, 15 Jan 2013 01:12:17 +0200 |
| parents | 15a391919deb |
| children | 89c6495d1ff2 |
line wrap: on
line diff
--- a/Modules/parsermodule.c Tue Jan 15 00:41:43 2013 +0200 +++ b/Modules/parsermodule.c Tue Jan 15 01:12:17 2013 +0200 @@ -725,7 +725,7 @@ /* elem must always be a sequence, however simple */ PyObject* elem = PySequence_GetItem(tuple, i); int ok = elem != NULL; - long type = 0; + int type = 0; char *strn = 0; if (ok) @@ -736,8 +736,14 @@ ok = 0; else { ok = PyLong_Check(temp); - if (ok) - type = PyLong_AS_LONG(temp); + if (ok) { + type = _PyLong_AsInt(temp); + if (type == -1 && PyErr_Occurred()) { + Py_DECREF(temp); + Py_DECREF(elem); + return 0; + } + } Py_DECREF(temp); } } @@ -773,8 +779,16 @@ if (len == 3) { PyObject *o = PySequence_GetItem(elem, 2); if (o != NULL) { - if (PyLong_Check(o)) - *line_num = PyLong_AS_LONG(o); + if (PyLong_Check(o)) { + int num = _PyLong_AsInt(o); + if (num == -1 && PyErr_Occurred()) { + Py_DECREF(o); + Py_DECREF(temp); + Py_DECREF(elem); + return 0; + } + *line_num = num; + } else { PyErr_Format(parser_error, "third item in terminal node must be an"
