Index: contrib/tzcode/stdtime/localtime.c =================================================================== --- contrib/tzcode/stdtime/localtime.c +++ contrib/tzcode/stdtime/localtime.c @@ -1521,7 +1521,7 @@ struct tm * gmtime(const time_t *const timep) { - struct tm *p_tm; + struct tm *p_tm, *res; if (__isthreaded != 0) { _pthread_once(&gmtime_once, gmtime_key_init); @@ -1540,12 +1540,12 @@ } _pthread_setspecific(gmtime_key, p_tm); } - gmtsub(timep, 0L, p_tm); - return(p_tm); + res = gmtsub(timep, 0L, p_tm); + return (res); } else { - gmtsub(timep, 0L, &tm); - return(&tm); + res = gmtsub(timep, 0L, &tm); + return (res); } } @@ -1638,13 +1638,17 @@ tdelta = tdays / DAYSPERLYEAR; idelta = tdelta; - if (tdelta - idelta >= 1 || idelta - tdelta >= 1) + if (tdelta - idelta >= 1 || idelta - tdelta >= 1) { + errno = EOVERFLOW; return NULL; + } if (idelta == 0) idelta = (tdays < 0) ? -1 : 1; newy = y; - if (increment_overflow(&newy, idelta)) + if (increment_overflow(&newy, idelta)) { + errno = EOVERFLOW; return NULL; + } leapdays = leaps_thru_end_of(newy - 1) - leaps_thru_end_of(y - 1); tdays -= ((time_t) newy - y) * DAYSPERNYEAR; @@ -1672,18 +1676,24 @@ ++idays; } while (idays < 0) { - if (increment_overflow(&y, -1)) + if (increment_overflow(&y, -1)) { + errno = EOVERFLOW; return NULL; + } idays += year_lengths[isleap(y)]; } while (idays >= year_lengths[isleap(y)]) { idays -= year_lengths[isleap(y)]; - if (increment_overflow(&y, 1)) + if (increment_overflow(&y, 1)) { + errno = EOVERFLOW; return NULL; + } } tmp->tm_year = y; - if (increment_overflow(&tmp->tm_year, -TM_YEAR_BASE)) + if (increment_overflow(&tmp->tm_year, -TM_YEAR_BASE)) { + errno = EOVERFLOW; return NULL; + } tmp->tm_yday = idays; /* ** The "extra" mods below avoid overflow problems.