From 56528fc710dcd6b182d3d7b34e744b5dbbf09e4d Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Thu, 19 Dec 2013 10:32:43 +0000
Subject: [PATCH] main/musl: fix hangs in localtime

---
 ...ocaltime-for-near-overflowing-time_t.patch | 25 +++++++++++++++++++
 main/musl/APKBUILD                            |  6 ++++-
 2 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 main/musl/1006-fix-hangs-in-localtime-for-near-overflowing-time_t.patch

diff --git a/main/musl/1006-fix-hangs-in-localtime-for-near-overflowing-time_t.patch b/main/musl/1006-fix-hangs-in-localtime-for-near-overflowing-time_t.patch
new file mode 100644
index 000000000000..a9f2e8e99135
--- /dev/null
+++ b/main/musl/1006-fix-hangs-in-localtime-for-near-overflowing-time_t.patch
@@ -0,0 +1,25 @@
+From f89e29829029c5003450f7b58bd00fe5d1049d09 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Thu, 19 Dec 2013 10:05:13 +0000
+Subject: fix hangs in localtime for near-overflowing time_t values on 64-bit archs
+
+---
+diff --git a/src/time/localtime_r.c b/src/time/localtime_r.c
+index c52678f..1d43d9f 100644
+--- a/src/time/localtime_r.c
++++ b/src/time/localtime_r.c
+@@ -4,6 +4,12 @@
+ 
+ struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm)
+ {
++	/* Reject time_t values whose year would overflow int because
++	 * __secs_to_zone cannot safely handle them. */
++	if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) {
++		errno = EOVERFLOW;
++		return 0;
++	}
+ 	__secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone);
+ 	if (__secs_to_tm((long long)*t - tm->__tm_gmtoff, tm) < 0) {
+ 		errno = EOVERFLOW;
+--
+cgit v0.9.0.3-65-g4555
diff --git a/main/musl/APKBUILD b/main/musl/APKBUILD
index 035eba463c8b..dff57807b1a8 100644
--- a/main/musl/APKBUILD
+++ b/main/musl/APKBUILD
@@ -2,7 +2,7 @@
 # Maintainer: Timo Teräs <timo.teras@iki.fi>
 pkgname=musl
 pkgver=0.9.14
-pkgrel=9
+pkgrel=10
 pkgdesc="the musl c library (libc) implementation"
 url="http://www.musl-libc.org/"
 arch="all"
@@ -21,6 +21,7 @@ source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz
 	1003-add-netinet-igmp.h-and-multicast-groups-to-netinet-i.patch
 	1004-define-and-implement-herror.patch
 	1005-add-TCP_INFO-and-TCP_MD5SIG-socket-option-related-st.patch
+	1006-fix-hangs-in-localtime-for-near-overflowing-time_t.patch
 
 	2001-workaround-gcc-pr58245.patch
 
@@ -120,6 +121,7 @@ a3810683ef61ac27e2f6ec9801280c81  1001-add-basic-dns-record-parsing-functions.pa
 bb7b6eb67c1749943f378c88acc48e5c  1003-add-netinet-igmp.h-and-multicast-groups-to-netinet-i.patch
 fcf15ee683ea241ad26330c28934fa27  1004-define-and-implement-herror.patch
 e46d5241827593673a3d8f1a6b8bacdc  1005-add-TCP_INFO-and-TCP_MD5SIG-socket-option-related-st.patch
+6cb4691d52d1567346e648567df283de  1006-fix-hangs-in-localtime-for-near-overflowing-time_t.patch
 7a09c5cd7b3e9532e6902f54a5e928bb  2001-workaround-gcc-pr58245.patch
 61c6c1e84ed1df82abbe6d75e90cf21c  getopt_long.c
 0df687757221bbb0fc1aa67f1bd646f9  __stack_chk_fail_local.c
@@ -132,6 +134,7 @@ d8e303e61f2cc220ce2b7ffd992d37406b87dd2a4062f61f5de3e0df144227b0  0001-updates-f
 f57dee5a9309055b298056e4d4107c67e3b0d5f164ab277ffcb353fb1688a2d2  1003-add-netinet-igmp.h-and-multicast-groups-to-netinet-i.patch
 995d3e6a7013f220cf3fdeae7ebfd84a1dc2517ebf53e712ab10c8b379e8ac9e  1004-define-and-implement-herror.patch
 2fb0f1b6f7f0092f5f8f144cede321ad375379e93805440af538d2be846d0c24  1005-add-TCP_INFO-and-TCP_MD5SIG-socket-option-related-st.patch
+3efe2d67f6e1601dd1c946f79e142dc1c4aeb8f1d3256bf48dec2057a506d5fe  1006-fix-hangs-in-localtime-for-near-overflowing-time_t.patch
 45d6efda7450809e4e68f6e951431dcadf6cb7f0260930d50a9f1a8667aca49f  2001-workaround-gcc-pr58245.patch
 d9b644ec20bc33e81a7c52b9fcf7973d835923a69faf50f03db45534b811bd96  getopt_long.c
 299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da  __stack_chk_fail_local.c
@@ -144,6 +147,7 @@ c64a8c5fa7f0ad095e9281cf23eeed70f476adadb044eb8ac8e038153fd19accf601d82cf89dc289
 a8bb390658552b766c1d92cf261bc77bd2369cd185d9803f2ba0265713de16f812dfe916a4d1b428bf5073848741800d856571009042e7514098344d31751f45  1003-add-netinet-igmp.h-and-multicast-groups-to-netinet-i.patch
 c510abb133aedc25a421837ee9e8e02d22d512fab2534d7ac612c2df1df28484d4a7e9ccef0ceec85ba2fb27ecea916d242dfbfff13159d22c4da4757a06e4f5  1004-define-and-implement-herror.patch
 a6bd33dcd80a525b9aacb5947ed294fd67148b83c02b139dcb8af39aaff0a27964aa6a640b07331d0f433df22ca3f177d7422b61917d42307cefddf7352002e5  1005-add-TCP_INFO-and-TCP_MD5SIG-socket-option-related-st.patch
+0ffe19fad7a8c572cd9f8a5bb7dec02fe9ac9555a09f74008fa7d7741e76a969e087670f132038c2a238b523b8c636bbc82e1f29db6b77b195d7b3b8efd90137  1006-fix-hangs-in-localtime-for-near-overflowing-time_t.patch
 69ad3fc851b44f33dd7c98b83fd0adbd149b37263d17b989f4d7338ee0703dfe8994f4299744e2509492300227d652de6f21b6cdba9b633fcefd3d9f7ca0cf20  2001-workaround-gcc-pr58245.patch
 140f3f20d30bd95ebce8c41b8cc7f616c6cbedf4ea06c729c21014e74f6043796825cc40ebc5180620ea38173afdba23f09ebf6d8b11fa05440b14d23764fca9  getopt_long.c
 062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b  __stack_chk_fail_local.c
-- 
GitLab