bpo-13312: Avoid int underflow in time year. (GH-8912)

Avoids an integer underflow in the time module's year handling code.
This commit is contained in:
Gregory P. Smith 2018-08-24 18:08:50 -07:00 committed by GitHub
parent eb746dbae8
commit 76be0fffff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 6 deletions

View file

@ -551,6 +551,12 @@ gettmarg(PyObject *args, struct tm *p, const char *format)
&p->tm_hour, &p->tm_min, &p->tm_sec,
&p->tm_wday, &p->tm_yday, &p->tm_isdst))
return 0;
if (y < INT_MIN + 1900) {
PyErr_SetString(PyExc_OverflowError, "year out of range");
return 0;
}
p->tm_year = y - 1900;
p->tm_mon--;
p->tm_wday = (p->tm_wday + 1) % 7;