diff options
| author | Theo Buehler <tb@openbsd.org> | 2024-05-25 08:56:45 +0200 |
|---|---|---|
| committer | Theo Buehler <tb@openbsd.org> | 2024-05-25 13:49:18 +0200 |
| commit | f9874d49f651177d643cc86f8837db44c4a29558 (patch) | |
| tree | 46e390fc24c101016532011a8b960903a4ee7b9b | |
| parent | f785e2954a847ebaa8559b65c2b5030489ce5556 (diff) | |
| download | portable-f9874d49f651177d643cc86f8837db44c4a29558.tar.gz portable-f9874d49f651177d643cc86f8837db44c4a29558.tar.bz2 portable-f9874d49f651177d643cc86f8837db44c4a29558.zip | |
Remove timegm() compat
Now that all uses of gmtime_r() and timegm() have been converted to
OPENSSL_gmtime() and OPENSSL_timegm(), this is no longer needed.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | CMakeLists.txt | 5 | ||||
| -rw-r--r-- | crypto/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | crypto/Makefile.am | 4 | ||||
| -rw-r--r-- | crypto/compat/timegm.c | 220 | ||||
| -rw-r--r-- | include/compat/time.h | 9 | ||||
| -rw-r--r-- | m4/check-libc.m4 | 1 |
7 files changed, 0 insertions, 245 deletions
| @@ -241,7 +241,6 @@ include/openssl/*.h | |||
| 241 | !/crypto/compat/getpagesize.c | 241 | !/crypto/compat/getpagesize.c |
| 242 | !/crypto/compat/posix_win.c | 242 | !/crypto/compat/posix_win.c |
| 243 | !/crypto/compat/bsd_asprintf.c | 243 | !/crypto/compat/bsd_asprintf.c |
| 244 | !/crypto/compat/timegm.c | ||
| 245 | !/crypto/compat/ui_openssl_win.c | 244 | !/crypto/compat/ui_openssl_win.c |
| 246 | !/crypto/compat/crypto_lock_win.c | 245 | !/crypto/compat/crypto_lock_win.c |
| 247 | !/crypto/CMakeLists.txt | 246 | !/crypto/CMakeLists.txt |
diff --git a/CMakeLists.txt b/CMakeLists.txt index 95fe601..438e622 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -255,11 +255,6 @@ if(HAVE_STRTONUM) | |||
| 255 | add_definitions(-DHAVE_STRTONUM) | 255 | add_definitions(-DHAVE_STRTONUM) |
| 256 | endif() | 256 | endif() |
| 257 | 257 | ||
| 258 | check_function_exists(timegm HAVE_TIMEGM) | ||
| 259 | if(HAVE_TIMEGM) | ||
| 260 | add_definitions(-DHAVE_TIMEGM) | ||
| 261 | endif() | ||
| 262 | |||
| 263 | check_function_exists(arc4random_buf HAVE_ARC4RANDOM_BUF) | 258 | check_function_exists(arc4random_buf HAVE_ARC4RANDOM_BUF) |
| 264 | if(HAVE_ARC4RANDOM_BUF) | 259 | if(HAVE_ARC4RANDOM_BUF) |
| 265 | add_definitions(-DHAVE_ARC4RANDOM_BUF) | 260 | add_definitions(-DHAVE_ARC4RANDOM_BUF) |
diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 5c0f3e6..b3e09b3 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt | |||
| @@ -721,11 +721,6 @@ if(NOT HAVE_SYSLOG_R) | |||
| 721 | set(COMPAT_SRC ${COMPAT_SRC} compat/syslog_r.c) | 721 | set(COMPAT_SRC ${COMPAT_SRC} compat/syslog_r.c) |
| 722 | endif() | 722 | endif() |
| 723 | 723 | ||
| 724 | if(NOT HAVE_TIMEGM) | ||
| 725 | # XXX - Remove after next bump once libtls, ocspcheck, and asn1time are fixed. | ||
| 726 | set(COMPAT_SRC ${COMPAT_SRC} compat/timegm.c) | ||
| 727 | endif() | ||
| 728 | |||
| 729 | if(NOT HAVE_EXPLICIT_BZERO) | 724 | if(NOT HAVE_EXPLICIT_BZERO) |
| 730 | if(WIN32) | 725 | if(WIN32) |
| 731 | set(COMPAT_SRC ${COMPAT_SRC} compat/explicit_bzero_win.c) | 726 | set(COMPAT_SRC ${COMPAT_SRC} compat/explicit_bzero_win.c) |
diff --git a/crypto/Makefile.am b/crypto/Makefile.am index 81d4524..08c632d 100644 --- a/crypto/Makefile.am +++ b/crypto/Makefile.am | |||
| @@ -147,10 +147,6 @@ endif | |||
| 147 | endif | 147 | endif |
| 148 | endif | 148 | endif |
| 149 | 149 | ||
| 150 | if !HAVE_TIMEGM | ||
| 151 | libcompat_la_SOURCES += compat/timegm.c | ||
| 152 | endif | ||
| 153 | |||
| 154 | if !HAVE_REALLOCARRAY | 150 | if !HAVE_REALLOCARRAY |
| 155 | libcompat_la_SOURCES += compat/reallocarray.c | 151 | libcompat_la_SOURCES += compat/reallocarray.c |
| 156 | endif | 152 | endif |
diff --git a/crypto/compat/timegm.c b/crypto/compat/timegm.c deleted file mode 100644 index 2658445..0000000 --- a/crypto/compat/timegm.c +++ /dev/null | |||
| @@ -1,220 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * ---------------------------------------------------------------------- | ||
| 3 | * Copyright © 2005-2014 Rich Felker, et al. | ||
| 4 | * | ||
| 5 | * Permission is hereby granted, free of charge, to any person obtaining | ||
| 6 | * a copy of this software and associated documentation files (the | ||
| 7 | * "Software"), to deal in the Software without restriction, including | ||
| 8 | * without limitation the rights to use, copy, modify, merge, publish, | ||
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to | ||
| 10 | * permit persons to whom the Software is furnished to do so, subject to | ||
| 11 | * the following conditions: | ||
| 12 | * | ||
| 13 | * The above copyright notice and this permission notice shall be | ||
| 14 | * included in all copies or substantial portions of the Software. | ||
| 15 | * | ||
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 20 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| 21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | * ---------------------------------------------------------------------- | ||
| 24 | */ | ||
| 25 | |||
| 26 | #include <errno.h> | ||
| 27 | #include <limits.h> | ||
| 28 | #include <time.h> | ||
| 29 | |||
| 30 | /* 2000-03-01 (mod 400 year, immediately after feb29 */ | ||
| 31 | #define LEAPOCH (946684800LL + 86400*(31+29)) | ||
| 32 | |||
| 33 | #define DAYS_PER_400Y (365*400 + 97) | ||
| 34 | #define DAYS_PER_100Y (365*100 + 24) | ||
| 35 | #define DAYS_PER_4Y (365*4 + 1) | ||
| 36 | |||
| 37 | static int __month_to_secs(int month, int is_leap) | ||
| 38 | { | ||
| 39 | static const int secs_through_month[] = { | ||
| 40 | 0, 31*86400, 59*86400, 90*86400, | ||
| 41 | 120*86400, 151*86400, 181*86400, 212*86400, | ||
| 42 | 243*86400, 273*86400, 304*86400, 334*86400 }; | ||
| 43 | int t = secs_through_month[month]; | ||
| 44 | if (is_leap && month >= 2) t+=86400; | ||
| 45 | return t; | ||
| 46 | } | ||
| 47 | |||
| 48 | static long long __year_to_secs(long long year, int *is_leap) | ||
| 49 | { | ||
| 50 | if (year-2ULL <= 136) { | ||
| 51 | int y = year; | ||
| 52 | int leaps = (y-68)>>2; | ||
| 53 | if (!((y-68)&3)) { | ||
| 54 | leaps--; | ||
| 55 | if (is_leap) *is_leap = 1; | ||
| 56 | } else if (is_leap) *is_leap = 0; | ||
| 57 | return 31536000*(y-70) + 86400*leaps; | ||
| 58 | } | ||
| 59 | |||
| 60 | int cycles, centuries, leaps, rem; | ||
| 61 | |||
| 62 | if (!is_leap) is_leap = &(int){0}; | ||
| 63 | cycles = (year-100) / 400; | ||
| 64 | rem = (year-100) % 400; | ||
| 65 | if (rem < 0) { | ||
| 66 | cycles--; | ||
| 67 | rem += 400; | ||
| 68 | } | ||
| 69 | if (!rem) { | ||
| 70 | *is_leap = 1; | ||
| 71 | centuries = 0; | ||
| 72 | leaps = 0; | ||
| 73 | } else { | ||
| 74 | if (rem >= 200) { | ||
| 75 | if (rem >= 300) centuries = 3, rem -= 300; | ||
| 76 | else centuries = 2, rem -= 200; | ||
| 77 | } else { | ||
| 78 | if (rem >= 100) centuries = 1, rem -= 100; | ||
| 79 | else centuries = 0; | ||
| 80 | } | ||
| 81 | if (!rem) { | ||
| 82 | *is_leap = 0; | ||
| 83 | leaps = 0; | ||
| 84 | } else { | ||
| 85 | leaps = rem / 4U; | ||
| 86 | rem %= 4U; | ||
| 87 | *is_leap = !rem; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | leaps += 97*cycles + 24*centuries - *is_leap; | ||
| 92 | |||
| 93 | return (year-100) * 31536000LL + leaps * 86400LL + 946684800 + 86400; | ||
| 94 | } | ||
| 95 | |||
| 96 | static long long __tm_to_secs(const struct tm *tm) | ||
| 97 | { | ||
| 98 | int is_leap; | ||
| 99 | long long year = tm->tm_year; | ||
| 100 | int month = tm->tm_mon; | ||
| 101 | if (month >= 12 || month < 0) { | ||
| 102 | int adj = month / 12; | ||
| 103 | month %= 12; | ||
| 104 | if (month < 0) { | ||
| 105 | adj--; | ||
| 106 | month += 12; | ||
| 107 | } | ||
| 108 | year += adj; | ||
| 109 | } | ||
| 110 | long long t = __year_to_secs(year, &is_leap); | ||
| 111 | t += __month_to_secs(month, is_leap); | ||
| 112 | t += 86400LL * (tm->tm_mday-1); | ||
| 113 | t += 3600LL * tm->tm_hour; | ||
| 114 | t += 60LL * tm->tm_min; | ||
| 115 | t += tm->tm_sec; | ||
| 116 | return t; | ||
| 117 | } | ||
| 118 | |||
| 119 | static int __secs_to_tm(long long t, struct tm *tm) | ||
| 120 | { | ||
| 121 | long long days, secs; | ||
| 122 | int remdays, remsecs, remyears; | ||
| 123 | int qc_cycles, c_cycles, q_cycles; | ||
| 124 | int years, months; | ||
| 125 | int wday, yday, leap; | ||
| 126 | static const char days_in_month[] = {31,30,31,30,31,31,30,31,30,31,31,29}; | ||
| 127 | |||
| 128 | /* Reject time_t values whose year would overflow int */ | ||
| 129 | if (t < INT_MIN * 31622400LL || t > INT_MAX * 31622400LL) | ||
| 130 | return -1; | ||
| 131 | |||
| 132 | secs = t - LEAPOCH; | ||
| 133 | days = secs / 86400; | ||
| 134 | remsecs = secs % 86400; | ||
| 135 | if (remsecs < 0) { | ||
| 136 | remsecs += 86400; | ||
| 137 | days--; | ||
| 138 | } | ||
| 139 | |||
| 140 | wday = (3+days)%7; | ||
| 141 | if (wday < 0) wday += 7; | ||
| 142 | |||
| 143 | qc_cycles = days / DAYS_PER_400Y; | ||
| 144 | remdays = days % DAYS_PER_400Y; | ||
| 145 | if (remdays < 0) { | ||
| 146 | remdays += DAYS_PER_400Y; | ||
| 147 | qc_cycles--; | ||
| 148 | } | ||
| 149 | |||
| 150 | c_cycles = remdays / DAYS_PER_100Y; | ||
| 151 | if (c_cycles == 4) c_cycles--; | ||
| 152 | remdays -= c_cycles * DAYS_PER_100Y; | ||
| 153 | |||
| 154 | q_cycles = remdays / DAYS_PER_4Y; | ||
| 155 | if (q_cycles == 25) q_cycles--; | ||
| 156 | remdays -= q_cycles * DAYS_PER_4Y; | ||
| 157 | |||
| 158 | remyears = remdays / 365; | ||
| 159 | if (remyears == 4) remyears--; | ||
| 160 | remdays -= remyears * 365; | ||
| 161 | |||
| 162 | leap = !remyears && (q_cycles || !c_cycles); | ||
| 163 | yday = remdays + 31 + 28 + leap; | ||
| 164 | if (yday >= 365+leap) yday -= 365+leap; | ||
| 165 | |||
| 166 | years = remyears + 4*q_cycles + 100*c_cycles + 400*qc_cycles; | ||
| 167 | |||
| 168 | for (months=0; days_in_month[months] <= remdays; months++) | ||
| 169 | remdays -= days_in_month[months]; | ||
| 170 | |||
| 171 | if (years+100 > INT_MAX || years+100 < INT_MIN) | ||
| 172 | return -1; | ||
| 173 | |||
| 174 | tm->tm_year = years + 100; | ||
| 175 | tm->tm_mon = months + 2; | ||
| 176 | if (tm->tm_mon >= 12) { | ||
| 177 | tm->tm_mon -=12; | ||
| 178 | tm->tm_year++; | ||
| 179 | } | ||
| 180 | tm->tm_mday = remdays + 1; | ||
| 181 | tm->tm_wday = wday; | ||
| 182 | tm->tm_yday = yday; | ||
| 183 | |||
| 184 | tm->tm_hour = remsecs / 3600; | ||
| 185 | tm->tm_min = remsecs / 60 % 60; | ||
| 186 | tm->tm_sec = remsecs % 60; | ||
| 187 | |||
| 188 | return 0; | ||
| 189 | } | ||
| 190 | |||
| 191 | #ifdef _WIN32 | ||
| 192 | struct tm *__gmtime_r(const time_t *t, struct tm *tm) | ||
| 193 | { | ||
| 194 | if (__secs_to_tm(*t, tm) < 0) { | ||
| 195 | errno = EOVERFLOW; | ||
| 196 | return 0; | ||
| 197 | } | ||
| 198 | tm->tm_isdst = 0; | ||
| 199 | return tm; | ||
| 200 | } | ||
| 201 | #endif | ||
| 202 | |||
| 203 | time_t timegm(struct tm *tm) | ||
| 204 | { | ||
| 205 | struct tm new; | ||
| 206 | long long t = __tm_to_secs(tm); | ||
| 207 | if (__secs_to_tm(t, &new) < 0) { | ||
| 208 | errno = EOVERFLOW; | ||
| 209 | return -1; | ||
| 210 | } | ||
| 211 | #if SIZEOF_TIME_T != 8 | ||
| 212 | if (t > (long long)INT_MAX || t < (long long)INT_MIN) { | ||
| 213 | errno = EOVERFLOW; | ||
| 214 | return -1; | ||
| 215 | } | ||
| 216 | #endif | ||
| 217 | *tm = new; | ||
| 218 | tm->tm_isdst = 0; | ||
| 219 | return t; | ||
| 220 | } | ||
diff --git a/include/compat/time.h b/include/compat/time.h index 2748521..a0f6d29 100644 --- a/include/compat/time.h +++ b/include/compat/time.h | |||
| @@ -24,15 +24,6 @@ | |||
| 24 | #ifndef LIBCRYPTOCOMPAT_TIME_H | 24 | #ifndef LIBCRYPTOCOMPAT_TIME_H |
| 25 | #define LIBCRYPTOCOMPAT_TIME_H | 25 | #define LIBCRYPTOCOMPAT_TIME_H |
| 26 | 26 | ||
| 27 | #ifdef _WIN32 | ||
| 28 | struct tm *__gmtime_r(const time_t * t, struct tm * tm); | ||
| 29 | #define gmtime_r(tp, tm) __gmtime_r(tp, tm) | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #ifndef HAVE_TIMEGM | ||
| 33 | time_t timegm(struct tm *tm); | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #ifndef CLOCK_MONOTONIC | 27 | #ifndef CLOCK_MONOTONIC |
| 37 | #define CLOCK_MONOTONIC CLOCK_REALTIME | 28 | #define CLOCK_MONOTONIC CLOCK_REALTIME |
| 38 | #endif | 29 | #endif |
diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index 50fb8e1..40df15b 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 | |||
| @@ -37,7 +37,6 @@ AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes]) | |||
| 37 | AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes]) | 37 | AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes]) |
| 38 | AM_CONDITIONAL([HAVE_STRSEP], [test "x$ac_cv_func_strsep" = xyes]) | 38 | AM_CONDITIONAL([HAVE_STRSEP], [test "x$ac_cv_func_strsep" = xyes]) |
| 39 | AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes]) | 39 | AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes]) |
| 40 | AM_CONDITIONAL([HAVE_TIMEGM], [test "x$ac_cv_func_timegm" = xyes]) | ||
| 41 | AM_CONDITIONAL([HAVE_GETPROGNAME], [test "x$ac_cv_func_getprogname" = xyes]) | 40 | AM_CONDITIONAL([HAVE_GETPROGNAME], [test "x$ac_cv_func_getprogname" = xyes]) |
| 42 | AM_CONDITIONAL([HAVE_SYSLOG], [test "x$ac_cv_func_syslog" = xyes]) | 41 | AM_CONDITIONAL([HAVE_SYSLOG], [test "x$ac_cv_func_syslog" = xyes]) |
| 43 | AM_CONDITIONAL([HAVE_SYSLOG_R], [test "x$ac_cv_func_syslog_r" = xyes]) | 42 | AM_CONDITIONAL([HAVE_SYSLOG_R], [test "x$ac_cv_func_syslog_r" = xyes]) |
