aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2017-10-12 00:51:20 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2017-10-12 00:51:20 +0000
commitafdba0ba0b8c0e92c376e7f1bfb151c07bf654b6 (patch)
tree8b8e5b58057c394a57e427ba8776a933c8377335 /main/musl
parentba95a098380de3c708a38dbecc0a8aae077d7574 (diff)
downloadaports-afdba0ba0b8c0e92c376e7f1bfb151c07bf654b6.tar.bz2
aports-afdba0ba0b8c0e92c376e7f1bfb151c07bf654b6.tar.xz
main/musl: update to alpine version 1.1.16-r21
- incorporate unreleased upstream bugfixes from august to present: - fix OOB reads in memmem implementations - fix undefined behaviour in memset - fix memory leak in clearenv - fix unicode processing bugs - fix signal masking issue with pthread_create - fix glob descent with GLOB_PERIOD - implement fopencookie(3)
Diffstat (limited to 'main/musl')
-rw-r--r--main/musl/0059-fix-erroneous-stop-before-input-limit-in-mbsnrtowcs-.patch78
-rw-r--r--main/musl/0060-fix-erroneous-acceptance-of-f4-9x-xx-xx-code-sequenc.patch30
-rw-r--r--main/musl/0061-fix-OOB-reads-in-Xbyte_memmem.patch54
-rw-r--r--main/musl/0062-free-allocations-in-clearenv.patch36
-rw-r--r--main/musl/0063-fix-undefined-behavior-in-memset-due-to-missing-sequ.patch39
-rw-r--r--main/musl/0064-handle-whitespace-before-in-scanf.patch61
-rw-r--r--main/musl/0065-make-syscall.h-consistent-with-linux.patch296
-rw-r--r--main/musl/0066-fix-signal-masking-race-in-pthread_create-with-prior.patch50
-rw-r--r--main/musl/0067-don-t-treat-numeric-port-strings-as-servent-records-.patch73
-rw-r--r--main/musl/0068-fix-glob-descent-into-.-and-.-with-GLOB_PERIOD.patch33
-rw-r--r--main/musl/0069-work-around-incorrect-EPERM-from-mmap-syscall.patch51
-rw-r--r--main/musl/0070-powerpc-64-fix-MAP_NORESERVE-and-MAP_LOCKED-in-mman..patch44
-rw-r--r--main/musl/0071-fix-use-of-memset-without-declaration-in-sched.h-cpu.patch29
-rw-r--r--main/musl/3002-stdio-implement-fopencookie-3.patch211
-rw-r--r--main/musl/APKBUILD31
15 files changed, 1115 insertions, 1 deletions
diff --git a/main/musl/0059-fix-erroneous-stop-before-input-limit-in-mbsnrtowcs-.patch b/main/musl/0059-fix-erroneous-stop-before-input-limit-in-mbsnrtowcs-.patch
new file mode 100644
index 0000000000..65b1cab4c1
--- /dev/null
+++ b/main/musl/0059-fix-erroneous-stop-before-input-limit-in-mbsnrtowcs-.patch
@@ -0,0 +1,78 @@
+From 11ddc314b57196519316103b02acffe10299dad3 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Thu, 31 Aug 2017 14:30:28 -0400
+Subject: [PATCH 1/2] fix erroneous stop before input limit in mbsnrtowcs and
+ wcsnrtombs
+
+the value computed as an output limit that bounds the amount of input
+consumed below the input limit was incorrectly being used as the
+actual amount of input consumed. instead, compute the actual amount of
+input consumed as a difference of pointers before and after the
+conversion.
+
+patch by Mikhail Kremnyov.
+---
+ src/multibyte/mbsnrtowcs.c | 4 +++-
+ src/multibyte/wcsnrtombs.c | 4 +++-
+ 2 files changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/src/multibyte/mbsnrtowcs.c b/src/multibyte/mbsnrtowcs.c
+index cae4caa2..931192e2 100644
+--- a/src/multibyte/mbsnrtowcs.c
++++ b/src/multibyte/mbsnrtowcs.c
+@@ -5,6 +5,7 @@ size_t mbsnrtowcs(wchar_t *restrict wcs, const char **restrict src, size_t n, si
+ size_t l, cnt=0, n2;
+ wchar_t *ws, wbuf[256];
+ const char *s = *src;
++ const char *tmp_s;
+
+ if (!wcs) ws = wbuf, wn = sizeof wbuf / sizeof *wbuf;
+ else ws = wcs;
+@@ -15,7 +16,7 @@ size_t mbsnrtowcs(wchar_t *restrict wcs, const char **restrict src, size_t n, si
+
+ while ( s && wn && ( (n2=n/4)>=wn || n2>32 ) ) {
+ if (n2>=wn) n2=wn;
+- n -= n2;
++ tmp_s = s;
+ l = mbsrtowcs(ws, &s, n2, st);
+ if (!(l+1)) {
+ cnt = l;
+@@ -26,6 +27,7 @@ size_t mbsnrtowcs(wchar_t *restrict wcs, const char **restrict src, size_t n, si
+ ws += l;
+ wn -= l;
+ }
++ n = s ? n - (s - tmp_s) : 0;
+ cnt += l;
+ }
+ if (s) while (wn && n) {
+diff --git a/src/multibyte/wcsnrtombs.c b/src/multibyte/wcsnrtombs.c
+index 640cbbeb..676932b5 100644
+--- a/src/multibyte/wcsnrtombs.c
++++ b/src/multibyte/wcsnrtombs.c
+@@ -5,13 +5,14 @@ size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, s
+ size_t l, cnt=0, n2;
+ char *s, buf[256];
+ const wchar_t *ws = *wcs;
++ const wchar_t *tmp_ws;
+
+ if (!dst) s = buf, n = sizeof buf;
+ else s = dst;
+
+ while ( ws && n && ( (n2=wn)>=n || n2>32 ) ) {
+ if (n2>=n) n2=n;
+- wn -= n2;
++ tmp_ws = ws;
+ l = wcsrtombs(s, &ws, n2, 0);
+ if (!(l+1)) {
+ cnt = l;
+@@ -22,6 +23,7 @@ size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, s
+ s += l;
+ n -= l;
+ }
++ wn = ws ? wn - (ws - tmp_ws) : 0;
+ cnt += l;
+ }
+ if (ws) while (n && wn) {
+--
+2.13.3
+
diff --git a/main/musl/0060-fix-erroneous-acceptance-of-f4-9x-xx-xx-code-sequenc.patch b/main/musl/0060-fix-erroneous-acceptance-of-f4-9x-xx-xx-code-sequenc.patch
new file mode 100644
index 0000000000..25dde60cc8
--- /dev/null
+++ b/main/musl/0060-fix-erroneous-acceptance-of-f4-9x-xx-xx-code-sequenc.patch
@@ -0,0 +1,30 @@
+From 39db00afadc9d8d0456c46eab42b8cb8ff9f375c Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Fri, 1 Sep 2017 17:05:40 -0400
+Subject: [PATCH 2/2] fix erroneous acceptance of f4 9x xx xx code sequences by
+ utf-8 decoder
+
+the DFA table controlling accepted ranges for the f4 prefix used an
+incorrect upper bound of 0xa0 where it should have been 0x90, allowing
+such sequences to be accepted and decoded as non-Unicode-scalar values
+0x110000 through 0x11ffff.
+---
+ src/multibyte/internal.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/multibyte/internal.c b/src/multibyte/internal.c
+index 7e1b1c03..2f5aaa91 100644
+--- a/src/multibyte/internal.c
++++ b/src/multibyte/internal.c
+@@ -9,7 +9,7 @@
+ | x )
+ #define F(x) ( ( x>=5 ? 0 : \
+ x==0 ? R(0x90,0xc0) : \
+- x==4 ? R(0x80,0xa0) : \
++ x==4 ? R(0x80,0x90) : \
+ R(0x80,0xc0) ) \
+ | ( R(0x80,0xc0) >> 6 ) \
+ | ( R(0x80,0xc0) >> 12 ) \
+--
+2.13.3
+
diff --git a/main/musl/0061-fix-OOB-reads-in-Xbyte_memmem.patch b/main/musl/0061-fix-OOB-reads-in-Xbyte_memmem.patch
new file mode 100644
index 0000000000..42684d8328
--- /dev/null
+++ b/main/musl/0061-fix-OOB-reads-in-Xbyte_memmem.patch
@@ -0,0 +1,54 @@
+From 51bdcdc424bd7169c8cccdc2de7cad17f5ea0f70 Mon Sep 17 00:00:00 2001
+From: Alexander Monakov <amonakov@ispras.ru>
+Date: Fri, 30 Jun 2017 00:35:33 +0300
+Subject: [PATCH 21/30] fix OOB reads in Xbyte_memmem
+
+Reported by Leah Neukirchen.
+---
+ src/string/memmem.c | 18 +++++++++---------
+ 1 file changed, 9 insertions(+), 9 deletions(-)
+
+diff --git a/src/string/memmem.c b/src/string/memmem.c
+index 4be6a310..54a66e46 100644
+--- a/src/string/memmem.c
++++ b/src/string/memmem.c
+@@ -5,27 +5,27 @@
+ static char *twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
+ {
+ uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1];
+- for (h++, k--; k; k--, hw = hw<<8 | *++h)
+- if (hw == nw) return (char *)h-1;
+- return 0;
++ for (h+=2, k-=2; k; k--, hw = hw<<8 | *h++)
++ if (hw == nw) return (char *)h-2;
++ return hw == nw ? (char *)h-2 : 0;
+ }
+
+ static char *threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
+ {
+ uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8;
+ uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8;
+- for (h+=2, k-=2; k; k--, hw = (hw|*++h)<<8)
+- if (hw == nw) return (char *)h-2;
+- return 0;
++ for (h+=3, k-=3; k; k--, hw = (hw|*h++)<<8)
++ if (hw == nw) return (char *)h-3;
++ return hw == nw ? (char *)h-3 : 0;
+ }
+
+ static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n)
+ {
+ uint32_t nw = n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3];
+ uint32_t hw = h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3];
+- for (h+=3, k-=3; k; k--, hw = hw<<8 | *++h)
+- if (hw == nw) return (char *)h-3;
+- return 0;
++ for (h+=4, k-=4; k; k--, hw = hw<<8 | *h++)
++ if (hw == nw) return (char *)h-4;
++ return hw == nw ? (char *)h-4 : 0;
+ }
+
+ #define MAX(a,b) ((a)>(b)?(a):(b))
+--
+2.13.3
+
diff --git a/main/musl/0062-free-allocations-in-clearenv.patch b/main/musl/0062-free-allocations-in-clearenv.patch
new file mode 100644
index 0000000000..a5bb4bca00
--- /dev/null
+++ b/main/musl/0062-free-allocations-in-clearenv.patch
@@ -0,0 +1,36 @@
+From cc0dbd5f09337c187156fe8b697245e6ea9263d0 Mon Sep 17 00:00:00 2001
+From: Alexander Monakov <amonakov@ispras.ru>
+Date: Sun, 3 Sep 2017 22:12:21 +0300
+Subject: free allocations in clearenv
+
+This aligns clearenv with the Linux man page by setting 'environ'
+rather than '*environ' to NULL, and stops it from leaking entries
+allocated by the libc.
+---
+ src/env/clearenv.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/src/env/clearenv.c b/src/env/clearenv.c
+index 62d5095..da18775 100644
+--- a/src/env/clearenv.c
++++ b/src/env/clearenv.c
+@@ -1,10 +1,14 @@
+ #define _GNU_SOURCE
+ #include <stdlib.h>
++#include "libc.h"
+
+-extern char **__environ;
++static void dummy(char *old, char *new) {}
++weak_alias(dummy, __env_rm_add);
+
+ int clearenv()
+ {
+- __environ[0] = 0;
++ char **e = __environ;
++ __environ = 0;
++ if (e) while (*e) __env_rm_add(*e++, 0);
+ return 0;
+ }
+--
+cgit v0.11.2
+
diff --git a/main/musl/0063-fix-undefined-behavior-in-memset-due-to-missing-sequ.patch b/main/musl/0063-fix-undefined-behavior-in-memset-due-to-missing-sequ.patch
new file mode 100644
index 0000000000..e247b7f404
--- /dev/null
+++ b/main/musl/0063-fix-undefined-behavior-in-memset-due-to-missing-sequ.patch
@@ -0,0 +1,39 @@
+From 9d4c902c42b3fda368d7ea64bb9575c46228fa7f Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Tue, 29 Aug 2017 19:53:50 -0400
+Subject: [PATCH 11/30] fix undefined behavior in memset due to missing
+ sequence points
+
+patch by Pascal Cuoq.
+---
+ src/string/memset.c | 12 ++++++++----
+ 1 file changed, 8 insertions(+), 4 deletions(-)
+
+diff --git a/src/string/memset.c b/src/string/memset.c
+index f438b073..5613a148 100644
+--- a/src/string/memset.c
++++ b/src/string/memset.c
+@@ -11,12 +11,16 @@ void *memset(void *dest, int c, size_t n)
+ * offsets are well-defined and in the dest region. */
+
+ if (!n) return dest;
+- s[0] = s[n-1] = c;
++ s[0] = c;
++ s[n-1] = c;
+ if (n <= 2) return dest;
+- s[1] = s[n-2] = c;
+- s[2] = s[n-3] = c;
++ s[1] = c;
++ s[2] = c;
++ s[n-2] = c;
++ s[n-3] = c;
+ if (n <= 6) return dest;
+- s[3] = s[n-4] = c;
++ s[3] = c;
++ s[n-4] = c;
+ if (n <= 8) return dest;
+
+ /* Advance pointer to align it at a 4-byte boundary,
+--
+2.13.3
+
diff --git a/main/musl/0064-handle-whitespace-before-in-scanf.patch b/main/musl/0064-handle-whitespace-before-in-scanf.patch
new file mode 100644
index 0000000000..f079ee3092
--- /dev/null
+++ b/main/musl/0064-handle-whitespace-before-in-scanf.patch
@@ -0,0 +1,61 @@
+From 9255dad97e7bfd4165d1aa0f93f2aae321a7a4d8 Mon Sep 17 00:00:00 2001
+From: Bartosz Brachaczek <b.brachaczek@gmail.com>
+Date: Sun, 9 Jul 2017 23:00:18 +0200
+Subject: [PATCH 22/30] handle whitespace before %% in scanf
+
+this is mandated by C and POSIX standards and is in accordance with
+glibc behavior.
+---
+ src/stdio/vfscanf.c | 10 +++++++---
+ src/stdio/vfwscanf.c | 8 ++++++--
+ 2 files changed, 13 insertions(+), 5 deletions(-)
+
+diff --git a/src/stdio/vfscanf.c b/src/stdio/vfscanf.c
+index d4d2454b..9e030fc4 100644
+--- a/src/stdio/vfscanf.c
++++ b/src/stdio/vfscanf.c
+@@ -89,15 +89,19 @@ int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap)
+ continue;
+ }
+ if (*p != '%' || p[1] == '%') {
+- p += *p=='%';
+ shlim(f, 0);
+- c = shgetc(f);
++ if (*p == '%') {
++ p++;
++ while (isspace((c=shgetc(f))));
++ } else {
++ c = shgetc(f);
++ }
+ if (c!=*p) {
+ shunget(f);
+ if (c<0) goto input_fail;
+ goto match_fail;
+ }
+- pos++;
++ pos += shcnt(f);
+ continue;
+ }
+
+diff --git a/src/stdio/vfwscanf.c b/src/stdio/vfwscanf.c
+index 1ebc5cef..a7cd0923 100644
+--- a/src/stdio/vfwscanf.c
++++ b/src/stdio/vfwscanf.c
+@@ -117,8 +117,12 @@ int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap)
+ continue;
+ }
+ if (*p != '%' || p[1] == '%') {
+- p += *p=='%';
+- c = getwc(f);
++ if (*p == '%') {
++ p++;
++ while (iswspace((c=getwc(f)))) pos++;
++ } else {
++ c = getwc(f);
++ }
+ if (c!=*p) {
+ ungetwc(c, f);
+ if (c<0) goto input_fail;
+--
+2.13.3
+
diff --git a/main/musl/0065-make-syscall.h-consistent-with-linux.patch b/main/musl/0065-make-syscall.h-consistent-with-linux.patch
new file mode 100644
index 0000000000..dd546aca7d
--- /dev/null
+++ b/main/musl/0065-make-syscall.h-consistent-with-linux.patch
@@ -0,0 +1,296 @@
+From 822dddfbf1884553341114663aff56ed87d57663 Mon Sep 17 00:00:00 2001
+From: Szabolcs Nagy <nsz@port70.net>
+Date: Sat, 18 Feb 2017 00:50:09 +0000
+Subject: [PATCH 23/30] make syscall.h consistent with linux
+
+most of the found naming differences don't matter to musl, because
+internally it unifies the syscall names that vary across targets,
+but for external code the names should match the kernel uapi.
+
+aarch64:
+ __NR_fstatat is called __NR_newfstatat in linux.
+ __NR_or1k_atomic got mistakenly copied from or1k.
+arm:
+ __NR_arm_sync_file_range is an alias for __NR_sync_file_range2
+ __NR_fadvise64_64 is called __NR_arm_fadvise64_64 in linux,
+ the old non-arm name is kept too, it should not cause issues.
+ (powerpc has similar nonstandard fadvise and it uses the
+ normal name.)
+i386:
+ __NR_madvise1 was removed from linux in commit
+ 303395ac3bf3e2cb488435537d416bc840438fcb 2011-11-11
+microblaze:
+ __NR_fadvise, __NR_fstatat, __NR_pread, __NR_pwrite
+ had different name in linux.
+mips:
+ __NR_fadvise, __NR_fstatat, __NR_pread, __NR_pwrite, __NR_select
+ had different name in linux.
+mipsn32:
+ __NR_fstatat is called __NR_newfstatat in linux.
+or1k:
+ __NR__llseek is called __NR_llseek in linux.
+ the old name is kept too because that's the name musl uses
+ internally.
+powerpc:
+ __NR_{get,set}res{gid,uid}32 was never present in powerpc linux.
+ __NR_timerfd was briefly defined in linux but then got renamed.
+---
+ arch/aarch64/bits/syscall.h.in | 3 +--
+ arch/arm/bits/syscall.h.in | 2 ++
+ arch/i386/bits/syscall.h.in | 1 -
+ arch/microblaze/bits/syscall.h.in | 8 ++++----
+ arch/mips/bits/syscall.h.in | 10 +++++-----
+ arch/mips/syscall_arch.h | 6 +++---
+ arch/mipsn32/bits/syscall.h.in | 2 +-
+ arch/mipsn32/syscall_arch.h | 6 +++---
+ arch/or1k/bits/syscall.h.in | 1 +
+ arch/powerpc/bits/syscall.h.in | 5 -----
+ 10 files changed, 20 insertions(+), 24 deletions(-)
+
+diff --git a/arch/aarch64/bits/syscall.h.in b/arch/aarch64/bits/syscall.h.in
+index fd388eec..8b56afff 100644
+--- a/arch/aarch64/bits/syscall.h.in
++++ b/arch/aarch64/bits/syscall.h.in
+@@ -77,7 +77,7 @@
+ #define __NR_splice 76
+ #define __NR_tee 77
+ #define __NR_readlinkat 78
+-#define __NR_fstatat 79
++#define __NR_newfstatat 79
+ #define __NR_fstat 80
+ #define __NR_sync 81
+ #define __NR_fsync 82
+@@ -242,7 +242,6 @@
+ #define __NR_perf_event_open 241
+ #define __NR_accept4 242
+ #define __NR_recvmmsg 243
+-#define __NR_or1k_atomic 244
+ #define __NR_wait4 260
+ #define __NR_prlimit64 261
+ #define __NR_fanotify_init 262
+diff --git a/arch/arm/bits/syscall.h.in b/arch/arm/bits/syscall.h.in
+index 9b129b23..0096fe7c 100644
+--- a/arch/arm/bits/syscall.h.in
++++ b/arch/arm/bits/syscall.h.in
+@@ -224,6 +224,7 @@
+ #define __NR_tgkill 268
+ #define __NR_utimes 269
+ #define __NR_fadvise64_64 270
++#define __NR_arm_fadvise64_64 270
+ #define __NR_pciconfig_iobase 271
+ #define __NR_pciconfig_read 272
+ #define __NR_pciconfig_write 273
+@@ -295,6 +296,7 @@
+ #define __NR_get_robust_list 339
+ #define __NR_splice 340
+ #define __NR_sync_file_range2 341
++#define __NR_arm_sync_file_range 341
+ #define __NR_tee 342
+ #define __NR_vmsplice 343
+ #define __NR_move_pages 344
+diff --git a/arch/i386/bits/syscall.h.in b/arch/i386/bits/syscall.h.in
+index 3a1d9270..1217f89a 100644
+--- a/arch/i386/bits/syscall.h.in
++++ b/arch/i386/bits/syscall.h.in
+@@ -218,7 +218,6 @@
+ #define __NR_pivot_root 217
+ #define __NR_mincore 218
+ #define __NR_madvise 219
+-#define __NR_madvise1 219
+ #define __NR_getdents64 220
+ #define __NR_fcntl64 221
+ /* 223 is unused */
+diff --git a/arch/microblaze/bits/syscall.h.in b/arch/microblaze/bits/syscall.h.in
+index 109fcdeb..e5f928e3 100644
+--- a/arch/microblaze/bits/syscall.h.in
++++ b/arch/microblaze/bits/syscall.h.in
+@@ -178,8 +178,8 @@
+ #define __NR_rt_sigtimedwait 177
+ #define __NR_rt_sigqueueinfo 178
+ #define __NR_rt_sigsuspend 179
+-#define __NR_pread 180
+-#define __NR_pwrite 181
++#define __NR_pread64 180
++#define __NR_pwrite64 181
+ #define __NR_chown 182
+ #define __NR_getcwd 183
+ #define __NR_capget 184
+@@ -246,7 +246,7 @@
+ #define __NR_io_getevents 247
+ #define __NR_io_submit 248
+ #define __NR_io_cancel 249
+-#define __NR_fadvise 250
++#define __NR_fadvise64 250
+ #define __NR_exit_group 252
+ #define __NR_lookup_dcookie 253
+ #define __NR_epoll_create 254
+@@ -294,7 +294,7 @@
+ #define __NR_mknodat 297
+ #define __NR_fchownat 298
+ #define __NR_futimesat 299
+-#define __NR_fstatat 300
++#define __NR_fstatat64 300
+ #define __NR_unlinkat 301
+ #define __NR_renameat 302
+ #define __NR_linkat 303
+diff --git a/arch/mips/bits/syscall.h.in b/arch/mips/bits/syscall.h.in
+index 6c9b3d8c..1a2147a7 100644
+--- a/arch/mips/bits/syscall.h.in
++++ b/arch/mips/bits/syscall.h.in
+@@ -140,7 +140,7 @@
+ #define __NR_setfsgid 4139
+ #define __NR__llseek 4140
+ #define __NR_getdents 4141
+-#define __NR_select 4142
++#define __NR__newselect 4142
+ #define __NR_flock 4143
+ #define __NR_msync 4144
+ #define __NR_readv 4145
+@@ -198,8 +198,8 @@
+ #define __NR_rt_sigtimedwait 4197
+ #define __NR_rt_sigqueueinfo 4198
+ #define __NR_rt_sigsuspend 4199
+-#define __NR_pread 4200
+-#define __NR_pwrite 4201
++#define __NR_pread64 4200
++#define __NR_pwrite64 4201
+ #define __NR_chown 4202
+ #define __NR_getcwd 4203
+ #define __NR_capget 4204
+@@ -252,7 +252,7 @@
+ #define __NR_remap_file_pages 4251
+ #define __NR_set_tid_address 4252
+ #define __NR_restart_syscall 4253
+-#define __NR_fadvise 4254
++#define __NR_fadvise64 4254
+ #define __NR_statfs64 4255
+ #define __NR_fstatfs64 4256
+ #define __NR_timer_create 4257
+@@ -290,7 +290,7 @@
+ #define __NR_mknodat 4290
+ #define __NR_fchownat 4291
+ #define __NR_futimesat 4292
+-#define __NR_fstatat 4293
++#define __NR_fstatat64 4293
+ #define __NR_unlinkat 4294
+ #define __NR_renameat 4295
+ #define __NR_linkat 4296
+diff --git a/arch/mips/syscall_arch.h b/arch/mips/syscall_arch.h
+index 3ac4da21..666f413f 100644
+--- a/arch/mips/syscall_arch.h
++++ b/arch/mips/syscall_arch.h
+@@ -99,7 +99,7 @@ static inline long __syscall4(long n, long a, long b, long c, long d)
+ if (r7) return -r2;
+ long ret = r2;
+ if (n == SYS_stat64 || n == SYS_fstat64 || n == SYS_lstat64) __stat_fix(b);
+- if (n == SYS_fstatat) __stat_fix(c);
++ if (n == SYS_fstatat64) __stat_fix(c);
+ return ret;
+ }
+
+@@ -108,7 +108,7 @@ static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+ long r2 = (__syscall)(n, a, b, c, d, e);
+ if (r2 > -4096UL) return r2;
+ if (n == SYS_stat64 || n == SYS_fstat64 || n == SYS_lstat64) __stat_fix(b);
+- if (n == SYS_fstatat) __stat_fix(c);
++ if (n == SYS_fstatat64) __stat_fix(c);
+ return r2;
+ }
+
+@@ -117,7 +117,7 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
+ long r2 = (__syscall)(n, a, b, c, d, e, f);
+ if (r2 > -4096UL) return r2;
+ if (n == SYS_stat64 || n == SYS_fstat64 || n == SYS_lstat64) __stat_fix(b);
+- if (n == SYS_fstatat) __stat_fix(c);
++ if (n == SYS_fstatat64) __stat_fix(c);
+ return r2;
+ }
+
+diff --git a/arch/mipsn32/bits/syscall.h.in b/arch/mipsn32/bits/syscall.h.in
+index d6b24e8f..cd843a76 100644
+--- a/arch/mipsn32/bits/syscall.h.in
++++ b/arch/mipsn32/bits/syscall.h.in
+@@ -253,7 +253,7 @@
+ #define __NR_mknodat 6253
+ #define __NR_fchownat 6254
+ #define __NR_futimesat 6255
+-#define __NR_fstatat 6256
++#define __NR_newfstatat 6256
+ #define __NR_unlinkat 6257
+ #define __NR_renameat 6258
+ #define __NR_linkat 6259
+diff --git a/arch/mipsn32/syscall_arch.h b/arch/mipsn32/syscall_arch.h
+index 37e71a7e..93a026f6 100644
+--- a/arch/mipsn32/syscall_arch.h
++++ b/arch/mipsn32/syscall_arch.h
+@@ -97,7 +97,7 @@ static inline long __syscall4(long n, long a, long b, long c, long d)
+ if (r7) return -r2;
+ long ret = r2;
+ if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b);
+- if (n == SYS_fstatat) __stat_fix(c);
++ if (n == SYS_newfstatat) __stat_fix(c);
+ return ret;
+ }
+
+@@ -106,7 +106,7 @@ static inline long __syscall5(long n, long a, long b, long c, long d, long e)
+ long r2 = (__syscall)(n, a, b, c, d, e);
+ if (r2 > -4096UL) return r2;
+ if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b);
+- if (n == SYS_fstatat) __stat_fix(c);
++ if (n == SYS_newfstatat) __stat_fix(c);
+ return r2;
+ }
+
+@@ -115,7 +115,7 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
+ long r2 = (__syscall)(n, a, b, c, d, e, f);
+ if (r2 > -4096UL) return r2;
+ if (n == SYS_stat || n == SYS_fstat || n == SYS_lstat) __stat_fix(b);
+- if (n == SYS_fstatat) __stat_fix(c);
++ if (n == SYS_newfstatat) __stat_fix(c);
+ return r2;
+ }
+
+diff --git a/arch/or1k/bits/syscall.h.in b/arch/or1k/bits/syscall.h.in
+index 89788a9d..54581fb4 100644
+--- a/arch/or1k/bits/syscall.h.in
++++ b/arch/or1k/bits/syscall.h.in
+@@ -61,6 +61,7 @@
+ #define __NR_quotactl 60
+ #define __NR_getdents64 61
+ #define __NR__llseek 62
++#define __NR_llseek 62
+ #define __NR_read 63
+ #define __NR_write 64
+ #define __NR_readv 65
+diff --git a/arch/powerpc/bits/syscall.h.in b/arch/powerpc/bits/syscall.h.in
+index 9d022321..35f7033e 100644
+--- a/arch/powerpc/bits/syscall.h.in
++++ b/arch/powerpc/bits/syscall.h.in
+@@ -162,16 +162,12 @@
+ #define __NR_sched_rr_get_interval 161
+ #define __NR_nanosleep 162
+ #define __NR_mremap 163
+-#define __NR_setresuid32 164
+ #define __NR_setresuid 164
+-#define __NR_getresuid32 165
+ #define __NR_getresuid 165
+ #define __NR_query_module 166
+ #define __NR_poll 167
+ #define __NR_nfsservctl 168
+-#define __NR_setresgid32 169
+ #define __NR_setresgid 169
+-#define __NR_getresgid32 170
+ #define __NR_getresgid 170
+ #define __NR_prctl 171
+ #define __NR_rt_sigreturn 172
+@@ -306,7 +302,6 @@
+ #define __NR_epoll_pwait 303
+ #define __NR_utimensat 304
+ #define __NR_signalfd 305
+-#define __NR_timerfd 306
+ #define __NR_timerfd_create 306
+ #define __NR_eventfd 307
+ #define __NR_sync_file_range2 308
+--
+2.13.3
+
diff --git a/main/musl/0066-fix-signal-masking-race-in-pthread_create-with-prior.patch b/main/musl/0066-fix-signal-masking-race-in-pthread_create-with-prior.patch
new file mode 100644
index 0000000000..ddf61e3962
--- /dev/null
+++ b/main/musl/0066-fix-signal-masking-race-in-pthread_create-with-prior.patch
@@ -0,0 +1,50 @@
+From 9e01be6e49b9ae433072207f420ef33c8189eb78 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Wed, 6 Sep 2017 20:37:19 -0400
+Subject: [PATCH 24/30] fix signal masking race in pthread_create with priority
+ attributes
+
+if the parent thread was able to set the new thread's priority before
+it reached the check for 'startlock', the new thread failed to restore
+its signal mask and thus ran with all signals blocked.
+
+concept for patch by Sergei, who reported the issue; unnecessary
+changes were removed and comments added since the whole 'startlock'
+thing is non-idiomatic and confusing. eventually it should be replaced
+with use of idiomatic synchronization primitives.
+---
+ src/thread/pthread_create.c | 9 +++++++--
+ 1 file changed, 7 insertions(+), 2 deletions(-)
+
+diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c
+index 49f2f729..6cbf85b3 100644
+--- a/src/thread/pthread_create.c
++++ b/src/thread/pthread_create.c
+@@ -131,9 +131,14 @@ void __do_cleanup_pop(struct __ptcb *cb)
+ static int start(void *p)
+ {
+ pthread_t self = p;
++ /* States for startlock:
++ * 0 = no need for start sync
++ * 1 = waiting for parent to do work
++ * 2 = failure in parent, child must abort
++ * 3 = success in parent, child must restore sigmask */
+ if (self->startlock[0]) {
+ __wait(self->startlock, 0, 1, 1);
+- if (self->startlock[0]) {
++ if (self->startlock[0] == 2) {
+ self->detached = 2;
+ pthread_exit(0);
+ }
+@@ -295,7 +300,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
+ if (do_sched) {
+ ret = __syscall(SYS_sched_setscheduler, new->tid,
+ attr._a_policy, &attr._a_prio);
+- a_store(new->startlock, ret<0 ? 2 : 0);
++ a_store(new->startlock, ret<0 ? 2 : 3);
+ __wake(new->startlock, 1, 1);
+ if (ret < 0) return -ret;
+ }
+--
+2.13.3
+
diff --git a/main/musl/0067-don-t-treat-numeric-port-strings-as-servent-records-.patch b/main/musl/0067-don-t-treat-numeric-port-strings-as-servent-records-.patch
new file mode 100644
index 0000000000..8e5fd0068e
--- /dev/null
+++ b/main/musl/0067-don-t-treat-numeric-port-strings-as-servent-records-.patch
@@ -0,0 +1,73 @@
+From 565dbee24d4bf55728be1c274fca1e7f3196fd73 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Wed, 6 Sep 2017 21:42:15 -0400
+Subject: [PATCH 25/30] don't treat numeric port strings as servent records in
+ getservby*()
+
+some applications use getservbyport to find port numbers that are not
+assigned to a service; if getservbyport always succeeds with a numeric
+string as the result, they fail to find any available ports.
+
+POSIX doesn't seem to mandate the behavior one way or another. it
+specifies an abstract service database, which an implementation could
+define to include numeric port strings, but it makes more sense to
+align behavior with traditional implementations.
+
+based on patch by A. Wilcox. the original patch only changed
+getservbyport[_r]. to maintain a consistent view of the "service
+database", I have also modified getservbyname[_r] to exclude numeric
+port strings.
+---
+ src/network/getservbyname_r.c | 6 ++++++
+ src/network/getservbyport_r.c | 4 ++++
+ 2 files changed, 10 insertions(+)
+
+diff --git a/src/network/getservbyname_r.c b/src/network/getservbyname_r.c
+index ad3d6164..cad6317a 100644
+--- a/src/network/getservbyname_r.c
++++ b/src/network/getservbyname_r.c
+@@ -5,6 +5,7 @@
+ #include <inttypes.h>
+ #include <errno.h>
+ #include <string.h>
++#include <stdlib.h>
+ #include "lookup.h"
+
+ #define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *))
+@@ -17,6 +18,11 @@ int getservbyname_r(const char *name, const char *prots,
+
+ *res = 0;
+
++ /* Don't treat numeric port number strings as service records. */
++ char *end = "";
++ strtoul(name, &end, 10);
++ if (!*end) return ENOENT;
++
+ /* Align buffer */
+ align = -(uintptr_t)buf & ALIGN-1;
+ if (buflen < 2*sizeof(char *)+align)
+diff --git a/src/network/getservbyport_r.c b/src/network/getservbyport_r.c
+index 0ae0e415..b7f21c6b 100644
+--- a/src/network/getservbyport_r.c
++++ b/src/network/getservbyport_r.c
+@@ -5,6 +5,7 @@
+ #include <inttypes.h>
+ #include <errno.h>
+ #include <string.h>
++#include <stdlib.h>
+
+ int getservbyport_r(int port, const char *prots,
+ struct servent *se, char *buf, size_t buflen, struct servent **res)
+@@ -51,6 +52,9 @@ int getservbyport_r(int port, const char *prots,
+ break;
+ }
+
++ /* A numeric port string is not a service record. */
++ if (strtol(buf, 0, 10)==ntohs(port)) return ENOENT;
++
+ *res = se;
+ return 0;
+ }
+--
+2.13.3
+
diff --git a/main/musl/0068-fix-glob-descent-into-.-and-.-with-GLOB_PERIOD.patch b/main/musl/0068-fix-glob-descent-into-.-and-.-with-GLOB_PERIOD.patch
new file mode 100644
index 0000000000..99f3547ed1
--- /dev/null
+++ b/main/musl/0068-fix-glob-descent-into-.-and-.-with-GLOB_PERIOD.patch
@@ -0,0 +1,33 @@
+From 8c4be3e2209d2a1d3874b8bc2b474668fcbbbac6 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Wed, 6 Sep 2017 21:59:22 -0400
+Subject: [PATCH 26/30] fix glob descent into . and .. with GLOB_PERIOD
+
+GLOB_PERIOD is a gnu extension, and GNU glob does not seem to honor it
+except in the last path component. it's not clear whether this a bug
+or intentional, but it seems reasonable that it should exclude the
+special entries . and .. when walking.
+
+changes based on report and analysis by Julien Ramseier.
+---
+ src/regex/glob.c | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/src/regex/glob.c b/src/regex/glob.c
+index 2d4d562e..6f8425ca 100644
+--- a/src/regex/glob.c
++++ b/src/regex/glob.c
+@@ -100,6 +100,10 @@ static int match_in_dir(const char *d, const char *p, int flags, int (*errfunc)(
+ continue;
+ if (p2 && de->d_type && !S_ISDIR(de->d_type<<12) && !S_ISLNK(de->d_type<<12))
+ continue;
++ if (p2 && de->d_name[0]=='.' && !de->d_name[1])
++ continue;
++ if (p2 && de->d_name[0]=='.' && de->d_name[1]=='.' && !de->d_name[2])
++ continue;
+ if (*d) {
+ memcpy(name, d, l);
+ name[l] = '/';
+--
+2.13.3
+
diff --git a/main/musl/0069-work-around-incorrect-EPERM-from-mmap-syscall.patch b/main/musl/0069-work-around-incorrect-EPERM-from-mmap-syscall.patch
new file mode 100644
index 0000000000..076f39c5ae
--- /dev/null
+++ b/main/musl/0069-work-around-incorrect-EPERM-from-mmap-syscall.patch
@@ -0,0 +1,51 @@
+From da438ee1fc516c41ba1790cef7be551a9e244397 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Wed, 6 Sep 2017 22:09:28 -0400
+Subject: [PATCH 27/30] work around incorrect EPERM from mmap syscall
+
+under some conditions, the mmap syscall wrongly fails with EPERM
+instead of ENOMEM when memory is exhausted; this is probably the
+result of the kernel trying to fit the allocation somewhere that
+crosses into the kernel range or below mmap_min_addr. in any case it's
+a conformance bug, so work around it. for now, only handle the case of
+anonymous mappings with no requested address; in other cases EPERM may
+be a legitimate error.
+
+this indirectly fixes the possibility of malloc failing with the wrong
+errno value.
+---
+ src/mman/mmap.c | 9 +++++++--
+ 1 file changed, 7 insertions(+), 2 deletions(-)
+
+diff --git a/src/mman/mmap.c b/src/mman/mmap.c
+index 19caadbd..15924033 100644
+--- a/src/mman/mmap.c
++++ b/src/mman/mmap.c
+@@ -14,6 +14,7 @@ weak_alias(dummy, __vm_wait);
+
+ void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
+ {
++ long ret;
+ if (off & OFF_MASK) {
+ errno = EINVAL;
+ return MAP_FAILED;
+@@ -26,10 +27,14 @@ void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
+ __vm_wait();
+ }
+ #ifdef SYS_mmap2
+- return (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
++ ret = __syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
+ #else
+- return (void *)syscall(SYS_mmap, start, len, prot, flags, fd, off);
++ ret = __syscall(SYS_mmap, start, len, prot, flags, fd, off);
+ #endif
++ /* Fixup incorrect EPERM from kernel. */
++ if (ret == -EPERM && !start && (flags&MAP_ANON) && !(flags&MAP_FIXED))
++ ret = -ENOMEM;
++ return (void *)__syscall_ret(ret);
+ }
+
+ weak_alias(__mmap, mmap);
+--
+2.13.3
+
diff --git a/main/musl/0070-powerpc-64-fix-MAP_NORESERVE-and-MAP_LOCKED-in-mman..patch b/main/musl/0070-powerpc-64-fix-MAP_NORESERVE-and-MAP_LOCKED-in-mman..patch
new file mode 100644
index 0000000000..8c6a8507a3
--- /dev/null
+++ b/main/musl/0070-powerpc-64-fix-MAP_NORESERVE-and-MAP_LOCKED-in-mman..patch
@@ -0,0 +1,44 @@
+From c10bc61508dc52b8315084e628f36a6c3c2dabb1 Mon Sep 17 00:00:00 2001
+From: Szabolcs Nagy <nsz@port70.net>
+Date: Sun, 10 Sep 2017 13:34:54 +0200
+Subject: [PATCH 28/30] powerpc{64}: fix MAP_NORESERVE and MAP_LOCKED in mman.h
+
+MAP_{NORESERVE,LOCKED} have different values on powerpc than in generic.
+---
+ arch/powerpc/bits/mman.h | 7 ++++++-
+ arch/powerpc64/bits/mman.h | 5 +++++
+ 2 files changed, 11 insertions(+), 1 deletion(-)
+
+diff --git a/arch/powerpc/bits/mman.h b/arch/powerpc/bits/mman.h
+index b6a15a12..95ec4358 100644
+--- a/arch/powerpc/bits/mman.h
++++ b/arch/powerpc/bits/mman.h
+@@ -1,4 +1,9 @@
+-#define PROT_SAO 0x10
++#define PROT_SAO 0x10
++
++#undef MAP_NORESERVE
++#define MAP_NORESERVE 0x40
++#undef MAP_LOCKED
++#define MAP_LOCKED 0x80
+
+ #undef MCL_CURRENT
+ #define MCL_CURRENT 0x2000
+diff --git a/arch/powerpc64/bits/mman.h b/arch/powerpc64/bits/mman.h
+index f5974f82..95ec4358 100644
+--- a/arch/powerpc64/bits/mman.h
++++ b/arch/powerpc64/bits/mman.h
+@@ -1,5 +1,10 @@
+ #define PROT_SAO 0x10
+
++#undef MAP_NORESERVE
++#define MAP_NORESERVE 0x40
++#undef MAP_LOCKED
++#define MAP_LOCKED 0x80
++
+ #undef MCL_CURRENT
+ #define MCL_CURRENT 0x2000
+ #undef MCL_FUTURE
+--
+2.13.3
+
diff --git a/main/musl/0071-fix-use-of-memset-without-declaration-in-sched.h-cpu.patch b/main/musl/0071-fix-use-of-memset-without-declaration-in-sched.h-cpu.patch
new file mode 100644
index 0000000000..2701b282d3
--- /dev/null
+++ b/main/musl/0071-fix-use-of-memset-without-declaration-in-sched.h-cpu.patch
@@ -0,0 +1,29 @@
+From 48be5b6313d7b827acf555769e93b389fa9f6307 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Thu, 28 Sep 2017 12:57:06 -0400
+Subject: [PATCH 29/30] fix use of memset without declaration in sched.h cpu
+ set macros
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+patch by Jörg Krause.
+---
+ include/sched.h | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/include/sched.h b/include/sched.h
+index d1cccb70..05d40b1e 100644
+--- a/include/sched.h
++++ b/include/sched.h
+@@ -72,6 +72,7 @@ int setns(int, int);
+
+ void *memcpy(void *__restrict, const void *__restrict, size_t);
+ int memcmp(const void *, const void *, size_t);
++void *memset (void *, int, size_t);
+ void *calloc(size_t, size_t);
+ void free(void *);
+
+--
+2.13.3
+
diff --git a/main/musl/3002-stdio-implement-fopencookie-3.patch b/main/musl/3002-stdio-implement-fopencookie-3.patch
new file mode 100644
index 0000000000..0c5eb63878
--- /dev/null
+++ b/main/musl/3002-stdio-implement-fopencookie-3.patch
@@ -0,0 +1,211 @@
+From b0949ba08f7b896593eaf27023a16a0f26c9ed14 Mon Sep 17 00:00:00 2001
+From: William Pitcock <nenolod@dereferenced.org>
+Date: Sun, 24 Sep 2017 16:37:48 -0500
+Subject: [PATCH 30/30] stdio: implement fopencookie(3)
+
+The fopencookie(3) function allows the programmer to create a custom
+stdio implementation, using four hook functions which operate on a
+"cookie" data type.
+
+Changelog:
+
+v6:
+- remove pointer arithmetic instead using a structure to contain the parent FILE
+ object
+- set F_ERR flag where appropriate
+- style fixes
+- fix stdio readahead to handle single-byte read case (as pointed out by dalias,
+ tested by custom fuzzer)
+- handle seek return values correctly (found by fuzzing)
+
+v5:
+- implement stdio readahead buffering support
+
+v4:
+- remove parameter names from header function declarations
+
+v3:
+- remove spurious `struct winsize`
+- make f->lock unconditionally 0
+
+v2:
+- properly implement stdio buffering
+
+v1:
+- initial proof of concept
+---
+ include/stdio.h | 9 ++++
+ src/stdio/fopencookie.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 150 insertions(+)
+ create mode 100644 src/stdio/fopencookie.c
+
+diff --git a/include/stdio.h b/include/stdio.h
+index 884d2e6a..da0563f6 100644
+--- a/include/stdio.h
++++ b/include/stdio.h
+@@ -182,6 +182,15 @@ int vasprintf(char **, const char *, __isoc_va_list);
+ #ifdef _GNU_SOURCE
+ char *fgets_unlocked(char *, int, FILE *);
+ int fputs_unlocked(const char *, FILE *);
++
++typedef struct {
++ ssize_t (*read)(void *, char *, size_t);
++ ssize_t (*write)(void *, const char *, size_t);
++ int (*seek)(void *, off_t *, int);
++ int (*close)(void *);
++} cookie_io_functions_t;
++
++FILE *fopencookie(void *, const char *, cookie_io_functions_t);
+ #endif
+
+ #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
+diff --git a/src/stdio/fopencookie.c b/src/stdio/fopencookie.c
+new file mode 100644
+index 00000000..bcf42c10
+--- /dev/null
++++ b/src/stdio/fopencookie.c
+@@ -0,0 +1,141 @@
++#define _GNU_SOURCE
++#include "stdio_impl.h"
++#include <stdlib.h>
++#include <sys/ioctl.h>
++#include <fcntl.h>
++#include <errno.h>
++#include <string.h>
++
++struct fcookie {
++ void *cookie;
++ cookie_io_functions_t iofuncs;
++};
++
++struct cookie_FILE {
++ FILE f;
++ struct fcookie fc;
++ unsigned char buf[UNGET+BUFSIZ];
++};
++
++static size_t cookieread(FILE *f, unsigned char *buf, size_t len)
++{
++ struct fcookie *fc = f->cookie;
++ ssize_t ret = -1;
++ size_t remain = len, readlen = 0;
++
++ if (!fc->iofuncs.read) goto bail;
++
++ ret = fc->iofuncs.read(fc->cookie, (char *) buf, len > 1 ? (len - 1) : 1);
++ if (ret <= 0) goto bail;
++
++ readlen += ret;
++ remain -= ret;
++
++ f->rpos = f->buf;
++ ret = fc->iofuncs.read(fc->cookie, (char *) f->rpos, f->buf_size);
++ if (ret <= 0) goto bail;
++ f->rend = f->rpos + ret;
++
++ if (remain > 0) {
++ if (remain > f->buf_size) remain = f->buf_size;
++ memcpy(buf + readlen, f->rpos, remain);
++ readlen += remain;
++ f->rpos += remain;
++ }
++
++ return readlen;
++
++bail:
++ f->flags |= F_EOF ^ ((F_ERR^F_EOF) & ret);
++ f->rpos = f->rend = f->buf;
++ return readlen;
++}
++
++static size_t cookiewrite(FILE *f, const unsigned char *buf, size_t len)
++{
++ struct fcookie *fc = f->cookie;
++ ssize_t ret;
++ size_t len2 = f->wpos - f->wbase;
++ if (!fc->iofuncs.write) return len;
++ if (len2) {
++ f->wpos = f->wbase;
++ if (cookiewrite(f, f->wpos, len2) < len2) return 0;
++ }
++ ret = fc->iofuncs.write(fc->cookie, (const char *) buf, len);
++ if (ret < 0) {
++ f->wpos = f->wbase = f->wend = 0;
++ f->flags |= F_ERR;
++ return 0;
++ }
++ return ret;
++}
++
++static off_t cookieseek(FILE *f, off_t off, int whence)
++{
++ struct fcookie *fc = f->cookie;
++ int res;
++ if (whence > 2) {
++ errno = EINVAL;
++ return -1;
++ }
++ if (!fc->iofuncs.seek) {
++ errno = ENOTSUP;
++ return -1;
++ }
++ res = fc->iofuncs.seek(fc->cookie, &off, whence);
++ if (res < 0)
++ return res;
++ return off;
++}
++
++static int cookieclose(FILE *f)
++{
++ struct fcookie *fc = f->cookie;
++ if (fc->iofuncs.close) return fc->iofuncs.close(fc->cookie);
++ return 0;
++}
++
++FILE *fopencookie(void *cookie, const char *mode, cookie_io_functions_t iofuncs)
++{
++ struct cookie_FILE *f;
++
++ /* Check for valid initial mode character */
++ if (!strchr("rwa", *mode)) {
++ errno = EINVAL;
++ return 0;
++ }
++
++ /* Allocate FILE+fcookie+buffer or fail */
++ if (!(f=malloc(sizeof *f))) return 0;
++
++ /* Zero-fill only the struct, not the buffer */
++ memset(f, 0, sizeof(FILE));
++
++ /* Impose mode restrictions */
++ if (!strchr(mode, '+')) f->f.flags = (*mode == 'r') ? F_NOWR : F_NORD;
++
++ /* Set up our fcookie */
++ f->fc.cookie = cookie;
++ f->fc.iofuncs.read = iofuncs.read;
++ f->fc.iofuncs.write = iofuncs.write;
++ f->fc.iofuncs.seek = iofuncs.seek;
++ f->fc.iofuncs.close = iofuncs.close;
++
++ f->f.fd = -1;
++ f->f.cookie = &f->fc;
++ f->f.buf = f->buf;
++ f->f.buf_size = BUFSIZ;
++ f->f.lbf = EOF;
++
++ /* enable opportunistic stdio locking */
++ f->f.lock = 0;
++
++ /* Initialize op ptrs. No problem if some are unneeded. */
++ f->f.read = cookieread;
++ f->f.write = cookiewrite;
++ f->f.seek = cookieseek;
++ f->f.close = cookieclose;
++
++ /* Add new FILE to open file list */
++ return __ofl_add(&f->f);
++}
+--
+2.13.3
+
diff --git a/main/musl/APKBUILD b/main/musl/APKBUILD
index cc5f3c86e9..36694d8780 100644
--- a/main/musl/APKBUILD
+++ b/main/musl/APKBUILD
@@ -2,7 +2,7 @@
# Maintainer: Timo Teräs <timo.teras@iki.fi>
pkgname=musl
pkgver=1.1.16
-pkgrel=20
+pkgrel=21
pkgdesc="the musl c library (libc) implementation"
url="http://www.musl-libc.org/"
arch="all"
@@ -75,10 +75,25 @@ source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz
0056-fix-undefined-behavior-in-free.patch
0057-fix-missing-volatile-qualifier-on-lock-in-__get_loca.patch
0058-ppc64-fix-setjmp-longjmp-handling-of-TOC-pointer.patch
+ 0059-fix-erroneous-stop-before-input-limit-in-mbsnrtowcs-.patch
+ 0060-fix-erroneous-acceptance-of-f4-9x-xx-xx-code-sequenc.patch
+ 0061-fix-OOB-reads-in-Xbyte_memmem.patch
+ 0062-free-allocations-in-clearenv.patch
+ 0063-fix-undefined-behavior-in-memset-due-to-missing-sequ.patch
+ 0064-handle-whitespace-before-in-scanf.patch
+ 0065-make-syscall.h-consistent-with-linux.patch
+ 0066-fix-signal-masking-race-in-pthread_create-with-prior.patch
+ 0067-don-t-treat-numeric-port-strings-as-servent-records-.patch
+ 0068-fix-glob-descent-into-.-and-.-with-GLOB_PERIOD.patch
+ 0069-work-around-incorrect-EPERM-from-mmap-syscall.patch
+ 0070-powerpc-64-fix-MAP_NORESERVE-and-MAP_LOCKED-in-mman..patch
+ 0071-fix-use-of-memset-without-declaration-in-sched.h-cpu.patch
+
1000-implement-strftime-GNU-extension-padding-specifiers-.patch
2000-pthread-internals-increase-DEFAULT_GUARD_SIZE-to-2-p.patch
2001-thread-do-not-attempt-to-join-detached-threads-in-pt.patch
3001-s390x-add-bits-hwcap.h.patch
+ 3002-stdio-implement-fopencookie-3.patch
0001-add-_NL_LOCALE_NAME-extension-to-nl_langinfo.patch
ldconfig
@@ -261,10 +276,24 @@ ea68e0c88430b65b5a61e4cbc6e6f477b383d34de89f21d59da50a05912f11a07b55de48b75cf4de
dde4bb6c877d4fdf976e3ffea5d0a4a48f365708c488ceeaa4dcc29296820517aebbfa3b0527d74ddb64bf6cdbac04624ba9043b884ac4cd770a848f4d0e1f88 0056-fix-undefined-behavior-in-free.patch
6e0a65d4023b4d2b0a971f1dbb5017fe7aedf7c663c0f9971841a4739758826c323cd0856a1591cfd874df35e8b96f1248eda029a9cd56987c36178a32b1f0ee 0057-fix-missing-volatile-qualifier-on-lock-in-__get_loca.patch
3fd640b606279eec9ee7551ca39903d3a9a91f30e5a78dbcc0e0a59fd7edec25dcafd24f50dc0f1065209b402c3f12720ed0180b49ff641dbd54bd83989f1dc9 0058-ppc64-fix-setjmp-longjmp-handling-of-TOC-pointer.patch
+4c3456e2539ac68ffc775bba5dca259f1ed2bc64a1b6824041223be118dc45968a85f07328f98b281e5d8254c363eaecafc745ccf3ac45b715f32071575916bd 0059-fix-erroneous-stop-before-input-limit-in-mbsnrtowcs-.patch
+4e42b8e7107ecad7abc1a580516b13c424c4b1cb21585539194486fe12e5b00ffad7986791aacf9b752580b5043d60acbe27092dd814dd4eaabdcff1a5c96266 0060-fix-erroneous-acceptance-of-f4-9x-xx-xx-code-sequenc.patch
+7e2cded73db0de17dd677352ac9770b4aab91f92ac1cdb50480e3a1cda1675e9028a19765b46e11e5fa860106e0c0a504073769a26112d467aa68b190f2d3806 0061-fix-OOB-reads-in-Xbyte_memmem.patch
+8d835abdbd384001033c0413dc899c94b522fa33b1f6ec05d86f6d999be97a229ded5e39e8cdb3e0a17d17d7bf1c9fb1e9da8479aa0115eda2c1e154071a528f 0062-free-allocations-in-clearenv.patch
+3a7f24c28e2eb5441753a6f245228607ff548de0d5aeaf4ce9107b982a5d2e827ae1ce0c60c465eb1d8ef95e0fda94cb31e0d01406217e5432b809bf6f5cc86f 0063-fix-undefined-behavior-in-memset-due-to-missing-sequ.patch
+2584506923d9e90bde6e58fa0a4030cd4c6ed6f1ef111c94c6a31a6a2ebd7514840484e2104a1584dacba9d17739de54a6281d92aad6a2c3ad93ab23495f374e 0064-handle-whitespace-before-in-scanf.patch
+745771bb87549f5ed52332214f0750ca741edd0aef84853e51c7e6e361ebe6bc354c0da6bfad74427fcc95b445ca7d887c771132465bc3515b362b4fdc66595a 0065-make-syscall.h-consistent-with-linux.patch
+07acf30dc8c2f221074d19798516ab7b79efeed307c6d26da7713e308133ec315c6f92d61fb25fe590c9be7810e461758902784370b3f725f8392d5d1750c762 0066-fix-signal-masking-race-in-pthread_create-with-prior.patch
+c50fab58e47c62252aa0e79a5c839e9b58a30b1f5d612a79cccc6d86a3fec25acf96be544141efdb20de24d25f870a7bb45527322b111678a9829e77428e7253 0067-don-t-treat-numeric-port-strings-as-servent-records-.patch
+e3de301bd48b7778e5370dee2945be6c78f6e50f9e5f18626c24635ec69115dacf4774a3da20afbeee01e95f0b4294d9d7761c3302949801efa8b7e34116d1f2 0068-fix-glob-descent-into-.-and-.-with-GLOB_PERIOD.patch
+46bed09ccded1680229dcf1dd851aca09363100481902bd85bc8f32dfc473968cbb06fa55d8221b2564684684c98fbe1a3ada503d3429c3cae9a1953a0f8c85d 0069-work-around-incorrect-EPERM-from-mmap-syscall.patch
+efb4b07f0c42c8ba2ca25bb9e76b312be1288e6d84c13a24e281dc343bd0bd3f24ee2b8b632500d1214473dfab81efdcb03de09014bc305ba09305402f2bc795 0070-powerpc-64-fix-MAP_NORESERVE-and-MAP_LOCKED-in-mman..patch
+4eee35c8030ab6b4b29e89cf250fe9853bc886edc3593320969a834a21e0a1ca225e3435c203c2d7de207c855063aabf635e464c94267110abb6509f289301ea 0071-fix-use-of-memset-without-declaration-in-sched.h-cpu.patch
7e4c703e57a3564cd3ee1d5334b806cbe654355179ba55d4d25361dfc555eb4a7d081d80d64fdaff8476949afd04558d278b124d1fb108080beaa5ba2f8ce2b9 1000-implement-strftime-GNU-extension-padding-specifiers-.patch
2c8e1dde1834238097b2ee8a7bfb53471a0d9cff4a5e38b55f048b567deff1cdd47c170d0578a67b1a039f95a6c5fbb8cff369c75b6a3e4d7ed171e8e86ebb8c 2000-pthread-internals-increase-DEFAULT_GUARD_SIZE-to-2-p.patch
76330dfff60b2a8703ddc38f378995334ab0fa56e31e499937a4b4dfd8ff4a0bf1f8108174e8f863810de5cc28ff4c50656b886ee468605072bc55310a077624 2001-thread-do-not-attempt-to-join-detached-threads-in-pt.patch
9c87849e6a58f393aaf4fa7dca31a010a369d41b2f24cdde6af0303df0436e2ef2ca5b767b5584b93f5c9c98e200ac2a972688b8ce2838a5ff9b746982085bcb 3001-s390x-add-bits-hwcap.h.patch
+0053e16cbac968b50dee98e3b36d29a497aaca6d9d0e120556273c9d0cd8360310eb7b7ab3c1e416217210fdd071e98268eaca54f3a0e9a22408ed8701dc54c1 3002-stdio-implement-fopencookie-3.patch
d725bb4990c5b2cdb88f6ecbe1f63895b29717c0ae3af60181588dd41cb10cd201f2faaade26f1abd31b568964a327131dad6f928717d953f44d7ef625ea8955 0001-add-_NL_LOCALE_NAME-extension-to-nl_langinfo.patch
8d3a2d5315fc56fee7da9abb8b89bb38c6046c33d154c10d168fb35bfde6b0cf9f13042a3bceee34daf091bc409d699223735dcf19f382eeee1f6be34154f26f ldconfig
062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c