diff -r f9dd607dc04c Modules/timemodule.c --- a/Modules/timemodule.c Tue Jan 03 02:01:42 2017 +0100 +++ b/Modules/timemodule.c Tue Jan 03 13:36:50 2017 +0100 @@ -279,11 +279,21 @@ static PyTypeObject StructTimeType; static PyObject * tmtotuple(struct tm *p #ifndef HAVE_STRUCT_TM_TM_ZONE - , const char *zone, int gmtoff + , const char *zone, time_t gmtoff #endif ) { - PyObject *v = PyStructSequence_New(&StructTimeType); + PyObject *v; + +#ifndef HAVE_STRUCT_TM_TM_ZONE + if (gmtoff < LONG_MIN || LONG_MAX < gmtoff) { + PyErr_SetString(PyExc_OverflowError, + "tm_gmtoff too large to fit in a C long"); + return NULL; + } +#endif + + v = PyStructSequence_New(&StructTimeType); if (v == NULL) return NULL; @@ -397,7 +407,7 @@ time_localtime(PyObject *self, PyObject { struct tm local = buf; char zone[100]; - int gmtoff; + time_t gmtoff; strftime(zone, sizeof(zone), "%Z", &buf); gmtoff = timegm(&buf) - when; return tmtotuple(&local, zone, gmtoff); @@ -1173,7 +1183,7 @@ get_zone(char *zone, int n, struct tm *p #endif } -static int +static time_t get_gmtoff(time_t t, struct tm *p) { #ifdef HAVE_STRUCT_TM_TM_ZONE