projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
harden realloc/free to detect simple overflows
[musl]
/
src
/
time
/
mktime.c
diff --git
a/src/time/mktime.c
b/src/time/mktime.c
index
858cd50
..
ef1fb42
100644
(file)
--- a/
src/time/mktime.c
+++ b/
src/time/mktime.c
@@
-1,24
+1,30
@@
-#include <time.h>
-
-#include "__time.h"
+#include "time_impl.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
time_t mktime(struct tm *tm)
{
time_t mktime(struct tm *tm)
{
- int isdst = tm->tm_isdst;
- time_t t, lt;
+ struct tm new;
+ long opp;
+ long long t = __tm_to_secs(tm);
+
+ __secs_to_zone(t, 1, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone);
- __tzset();
+ if (tm->tm_isdst>=0 && new.tm_isdst!=tm->tm_isdst)
+ t += opp - new.__tm_gmtoff;
- t
m->tm_sec += __timezone
;
- if (
isdst > 0) tm->tm_sec += __dst_offset
;
+ t
+= new.__tm_gmtoff
;
+ if (
(time_t)t != t) goto error
;
- t = __tm_to_time(tm);
-
- lt = t - __timezone;
- if (isdst > 0) lt -= __dst_offset;
- __time_to_tm(lt, tm);
+ __secs_to_zone(t, 0, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone);
- __dst_adjust(tm);
-
+ if (__secs_to_tm(t - new.__tm_gmtoff, &new) < 0) goto error;
+
+ *tm = new;
return t;
return t;
+
+error:
+ errno = EOVERFLOW;
+ return -1;
}
}