065-fix-integer-overflow-of-tm_year-in-__secs_to_tm.patch 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. From bc1e7731cee963e422575f81048792f4d5db9641 Mon Sep 17 00:00:00 2001
  2. From: Daniel Sabogal <[email protected]>
  3. Date: Wed, 2 Nov 2016 22:29:36 -0400
  4. Subject: fix integer overflow of tm_year in __secs_to_tm
  5. the overflow check for years+100 did not account for the extra
  6. year computed from the remaining months. instead, perform this
  7. check after obtaining the final number of years.
  8. ---
  9. src/time/__secs_to_tm.c | 9 +++++----
  10. 1 file changed, 5 insertions(+), 4 deletions(-)
  11. diff --git a/src/time/__secs_to_tm.c b/src/time/__secs_to_tm.c
  12. index 3a3123a..093d902 100644
  13. --- a/src/time/__secs_to_tm.c
  14. +++ b/src/time/__secs_to_tm.c
  15. @@ -60,15 +60,16 @@ int __secs_to_tm(long long t, struct tm *tm)
  16. for (months=0; days_in_month[months] <= remdays; months++)
  17. remdays -= days_in_month[months];
  18. + if (months >= 10) {
  19. + months -= 12;
  20. + years++;
  21. + }
  22. +
  23. if (years+100 > INT_MAX || years+100 < INT_MIN)
  24. return -1;
  25. tm->tm_year = years + 100;
  26. tm->tm_mon = months + 2;
  27. - if (tm->tm_mon >= 12) {
  28. - tm->tm_mon -=12;
  29. - tm->tm_year++;
  30. - }
  31. tm->tm_mday = remdays + 1;
  32. tm->tm_wday = wday;
  33. tm->tm_yday = yday;
  34. --
  35. cgit v0.11.2