Skip to content

Commit

Permalink
Fix 32-bit overflow in mktime() when time_t is 64-bits long
Browse files Browse the repository at this point in the history
When converting number of days since epoch (32-bits) to seconds,
calculations using 32-bit `long` overflow for years above 2038. Solve
this by casting number of days to `time_t` just before final
multiplication.

Signed-off-by: Freddie Chopin <[email protected]>
  • Loading branch information
FreddieChopin authored and kito-cheng committed Jun 5, 2018
1 parent e1c8dc3 commit af5af06
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion newlib/libc/time/mktime.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ mktime (struct tm *tim_p)
}

/* compute total seconds */
tim += (days * _SEC_IN_DAY);
tim += (time_t)days * _SEC_IN_DAY;

TZ_LOCK;

Expand Down

0 comments on commit af5af06

Please sign in to comment.