Issue 24773: Added a time_t overflow check.

This commit is contained in:
Alexander Belopolsky 2016-07-25 13:54:51 -04:00
parent 43b17134e9
commit 8e1d3a2d41
1 changed files with 8 additions and 1 deletions

View File

@ -4207,7 +4207,14 @@ static PY_LONG_LONG
local(PY_LONG_LONG u) local(PY_LONG_LONG u)
{ {
struct tm local_time; struct tm local_time;
time_t t = u - epoch; time_t t;
u -= epoch;
t = u;
if (t != u) {
PyErr_SetString(PyExc_OverflowError,
"timestamp out of range for platform time_t");
return -1;
}
/* XXX: add bounds checking */ /* XXX: add bounds checking */
if (localtime_r(&t, &local_time) == NULL) { if (localtime_r(&t, &local_time) == NULL) {
PyErr_SetFromErrno(PyExc_OSError); PyErr_SetFromErrno(PyExc_OSError);