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