main/musl: apply upstream fixes

This commit is contained in:
Timo Teräs 2017-01-12 08:18:00 +02:00
parent 9878b048b4
commit efe30cbdc1
5 changed files with 422 additions and 1 deletions

View File

@ -0,0 +1,258 @@
From 150747b41e1ecefe82aa45d68c84b9e957b03e29 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Wed, 4 Jan 2017 17:08:19 -0500
Subject: [PATCH] reduce impact of REG_* namespace pollution in x86[_64]
signal.h
when _GNU_SOURCE is defined, which is always the case when compiling
c++ with gcc, these macros for the the indices in gregset_t are
exposed and likely to clash with applications. by using enum constants
rather than macros defined with integer literals, we can make the
clash slightly less likely to break software. the macros are still
defined in case anything checks for them with #ifdef, but they're
defined to expand to themselves so that non-file-scope (e.g.
namespaced) identifiers by the same names still work.
for the sake of avoiding mistakes, the changes were generated with sed
via the command:
sed -i -e 's/#define *\(REG_[A-Z_0-9]\{1,\}\) *\([0-9]\{1,\}\)'\
'/enum { \1 = \2 };\n#define \1 \1/' \
arch/i386/bits/signal.h arch/x86_64/bits/signal.h arch/x32/bits/signal.h
---
arch/i386/bits/signal.h | 57 ++++++++++++++++++++++++++-------------
arch/x32/bits/signal.h | 69 +++++++++++++++++++++++++++++++----------------
arch/x86_64/bits/signal.h | 69 +++++++++++++++++++++++++++++++----------------
3 files changed, 130 insertions(+), 65 deletions(-)
diff --git a/arch/i386/bits/signal.h b/arch/i386/bits/signal.h
index 1f9085a5..9931ee93 100644
--- a/arch/i386/bits/signal.h
+++ b/arch/i386/bits/signal.h
@@ -7,25 +7,44 @@
#endif
#ifdef _GNU_SOURCE
-#define REG_GS 0
-#define REG_FS 1
-#define REG_ES 2
-#define REG_DS 3
-#define REG_EDI 4
-#define REG_ESI 5
-#define REG_EBP 6
-#define REG_ESP 7
-#define REG_EBX 8
-#define REG_EDX 9
-#define REG_ECX 10
-#define REG_EAX 11
-#define REG_TRAPNO 12
-#define REG_ERR 13
-#define REG_EIP 14
-#define REG_CS 15
-#define REG_EFL 16
-#define REG_UESP 17
-#define REG_SS 18
+enum { REG_GS = 0 };
+#define REG_GS REG_GS
+enum { REG_FS = 1 };
+#define REG_FS REG_FS
+enum { REG_ES = 2 };
+#define REG_ES REG_ES
+enum { REG_DS = 3 };
+#define REG_DS REG_DS
+enum { REG_EDI = 4 };
+#define REG_EDI REG_EDI
+enum { REG_ESI = 5 };
+#define REG_ESI REG_ESI
+enum { REG_EBP = 6 };
+#define REG_EBP REG_EBP
+enum { REG_ESP = 7 };
+#define REG_ESP REG_ESP
+enum { REG_EBX = 8 };
+#define REG_EBX REG_EBX
+enum { REG_EDX = 9 };
+#define REG_EDX REG_EDX
+enum { REG_ECX = 10 };
+#define REG_ECX REG_ECX
+enum { REG_EAX = 11 };
+#define REG_EAX REG_EAX
+enum { REG_TRAPNO = 12 };
+#define REG_TRAPNO REG_TRAPNO
+enum { REG_ERR = 13 };
+#define REG_ERR REG_ERR
+enum { REG_EIP = 14 };
+#define REG_EIP REG_EIP
+enum { REG_CS = 15 };
+#define REG_CS REG_CS
+enum { REG_EFL = 16 };
+#define REG_EFL REG_EFL
+enum { REG_UESP = 17 };
+#define REG_UESP REG_UESP
+enum { REG_SS = 18 };
+#define REG_SS REG_SS
#endif
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
diff --git a/arch/x32/bits/signal.h b/arch/x32/bits/signal.h
index 4c4adf31..097be6f4 100644
--- a/arch/x32/bits/signal.h
+++ b/arch/x32/bits/signal.h
@@ -7,29 +7,52 @@
#endif
#ifdef _GNU_SOURCE
-#define REG_R8 0
-#define REG_R9 1
-#define REG_R10 2
-#define REG_R11 3
-#define REG_R12 4
-#define REG_R13 5
-#define REG_R14 6
-#define REG_R15 7
-#define REG_RDI 8
-#define REG_RSI 9
-#define REG_RBP 10
-#define REG_RBX 11
-#define REG_RDX 12
-#define REG_RAX 13
-#define REG_RCX 14
-#define REG_RSP 15
-#define REG_RIP 16
-#define REG_EFL 17
-#define REG_CSGSFS 18
-#define REG_ERR 19
-#define REG_TRAPNO 20
-#define REG_OLDMASK 21
-#define REG_CR2 22
+enum { REG_R8 = 0 };
+#define REG_R8 REG_R8
+enum { REG_R9 = 1 };
+#define REG_R9 REG_R9
+enum { REG_R10 = 2 };
+#define REG_R10 REG_R10
+enum { REG_R11 = 3 };
+#define REG_R11 REG_R11
+enum { REG_R12 = 4 };
+#define REG_R12 REG_R12
+enum { REG_R13 = 5 };
+#define REG_R13 REG_R13
+enum { REG_R14 = 6 };
+#define REG_R14 REG_R14
+enum { REG_R15 = 7 };
+#define REG_R15 REG_R15
+enum { REG_RDI = 8 };
+#define REG_RDI REG_RDI
+enum { REG_RSI = 9 };
+#define REG_RSI REG_RSI
+enum { REG_RBP = 10 };
+#define REG_RBP REG_RBP
+enum { REG_RBX = 11 };
+#define REG_RBX REG_RBX
+enum { REG_RDX = 12 };
+#define REG_RDX REG_RDX
+enum { REG_RAX = 13 };
+#define REG_RAX REG_RAX
+enum { REG_RCX = 14 };
+#define REG_RCX REG_RCX
+enum { REG_RSP = 15 };
+#define REG_RSP REG_RSP
+enum { REG_RIP = 16 };
+#define REG_RIP REG_RIP
+enum { REG_EFL = 17 };
+#define REG_EFL REG_EFL
+enum { REG_CSGSFS = 18 };
+#define REG_CSGSFS REG_CSGSFS
+enum { REG_ERR = 19 };
+#define REG_ERR REG_ERR
+enum { REG_TRAPNO = 20 };
+#define REG_TRAPNO REG_TRAPNO
+enum { REG_OLDMASK = 21 };
+#define REG_OLDMASK REG_OLDMASK
+enum { REG_CR2 = 22 };
+#define REG_CR2 REG_CR2
#endif
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
diff --git a/arch/x86_64/bits/signal.h b/arch/x86_64/bits/signal.h
index e3c31417..c99317d3 100644
--- a/arch/x86_64/bits/signal.h
+++ b/arch/x86_64/bits/signal.h
@@ -7,29 +7,52 @@
#endif
#ifdef _GNU_SOURCE
-#define REG_R8 0
-#define REG_R9 1
-#define REG_R10 2
-#define REG_R11 3
-#define REG_R12 4
-#define REG_R13 5
-#define REG_R14 6
-#define REG_R15 7
-#define REG_RDI 8
-#define REG_RSI 9
-#define REG_RBP 10
-#define REG_RBX 11
-#define REG_RDX 12
-#define REG_RAX 13
-#define REG_RCX 14
-#define REG_RSP 15
-#define REG_RIP 16
-#define REG_EFL 17
-#define REG_CSGSFS 18
-#define REG_ERR 19
-#define REG_TRAPNO 20
-#define REG_OLDMASK 21
-#define REG_CR2 22
+enum { REG_R8 = 0 };
+#define REG_R8 REG_R8
+enum { REG_R9 = 1 };
+#define REG_R9 REG_R9
+enum { REG_R10 = 2 };
+#define REG_R10 REG_R10
+enum { REG_R11 = 3 };
+#define REG_R11 REG_R11
+enum { REG_R12 = 4 };
+#define REG_R12 REG_R12
+enum { REG_R13 = 5 };
+#define REG_R13 REG_R13
+enum { REG_R14 = 6 };
+#define REG_R14 REG_R14
+enum { REG_R15 = 7 };
+#define REG_R15 REG_R15
+enum { REG_RDI = 8 };
+#define REG_RDI REG_RDI
+enum { REG_RSI = 9 };
+#define REG_RSI REG_RSI
+enum { REG_RBP = 10 };
+#define REG_RBP REG_RBP
+enum { REG_RBX = 11 };
+#define REG_RBX REG_RBX
+enum { REG_RDX = 12 };
+#define REG_RDX REG_RDX
+enum { REG_RAX = 13 };
+#define REG_RAX REG_RAX
+enum { REG_RCX = 14 };
+#define REG_RCX REG_RCX
+enum { REG_RSP = 15 };
+#define REG_RSP REG_RSP
+enum { REG_RIP = 16 };
+#define REG_RIP REG_RIP
+enum { REG_EFL = 17 };
+#define REG_EFL REG_EFL
+enum { REG_CSGSFS = 18 };
+#define REG_CSGSFS REG_CSGSFS
+enum { REG_ERR = 19 };
+#define REG_ERR REG_ERR
+enum { REG_TRAPNO = 20 };
+#define REG_TRAPNO REG_TRAPNO
+enum { REG_OLDMASK = 21 };
+#define REG_OLDMASK REG_OLDMASK
+enum { REG_CR2 = 22 };
+#define REG_CR2 REG_CR2
#endif
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
--
2.11.0

View File

@ -0,0 +1,82 @@
From 786fda875a901dc1807289c940338487854cd3ba Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Wed, 4 Jan 2017 19:02:02 -0500
Subject: [PATCH] fix getopt[_long] clobbering of optopt on success
getopt is only specified to modify optopt on error, and some software
apparently infers an error from optopt!=0.
getopt_long is changed analogously. the resulting behavior differs
slightly from the behavior of the GNU implementation of getopt_long,
which keeps an internal shadow copy of optopt and copies it to the
public one on return, but since the GNU implementation also exhibits
this shadow-copy behavior for plain getopt where is is non-conforming,
I think this can reasonably be considered a bug rather than an
intentional behavior that merits mimicing.
---
src/misc/getopt.c | 3 ++-
src/misc/getopt_long.c | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/misc/getopt.c b/src/misc/getopt.c
index 8290aef7..e9bab41c 100644
--- a/src/misc/getopt.c
+++ b/src/misc/getopt.c
@@ -60,7 +60,6 @@ int getopt(int argc, char * const argv[], const char *optstring)
c = 0xfffd; /* replacement char */
}
optchar = argv[optind]+optpos;
- optopt = c;
optpos += k;
if (!argv[optind][optpos]) {
@@ -79,6 +78,7 @@ int getopt(int argc, char * const argv[], const char *optstring)
} while (l && d != c);
if (d != c) {
+ optopt = c;
if (optstring[0] != ':' && opterr)
__getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
return '?';
@@ -86,6 +86,7 @@ int getopt(int argc, char * const argv[], const char *optstring)
if (optstring[i] == ':') {
if (optstring[i+1] == ':') optarg = 0;
else if (optind >= argc) {
+ optopt = c;
if (optstring[0] == ':') return ':';
if (opterr) __getopt_msg(argv[0],
": option requires an argument: ",
diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c
index c6e14625..568ae7ba 100644
--- a/src/misc/getopt_long.c
+++ b/src/misc/getopt_long.c
@@ -75,9 +75,9 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
if (cnt==1) {
i = match;
optind++;
- optopt = longopts[i].val;
if (*opt == '=') {
if (!longopts[i].has_arg) {
+ optopt = longopts[i].val;
if (colon || !opterr)
return '?';
__getopt_msg(argv[0],
@@ -89,6 +89,7 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
optarg = opt+1;
} else if (longopts[i].has_arg == required_argument) {
if (!(optarg = argv[optind])) {
+ optopt = longopts[i].val;
if (colon) return ':';
if (!opterr) return '?';
__getopt_msg(argv[0],
@@ -107,6 +108,7 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
return longopts[i].val;
}
if (argv[optind][1] == '-') {
+ optopt = 0;
if (!colon && opterr)
__getopt_msg(argv[0], cnt ?
": option is ambiguous: " :
--
2.11.0

View File

@ -0,0 +1,31 @@
From 809ff8cf90254921ea38eb6fa1ce326d9008513b Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Wed, 4 Jan 2017 19:48:21 -0500
Subject: [PATCH] treat base 1 as an error in strtol-family functions
ISO C and POSIX only specify behavior for base arguments of 0 and
2-36; POSIX mandates an EINVAL error for unsupported bases. it's not
clear that there's a requirement for implementations not to "support"
additional bases as an extension, but "base 1" did not work in any
meaningful way anyway, so it should be considered unsupported and thus
an error.
---
src/internal/intscan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/internal/intscan.c b/src/internal/intscan.c
index 65d497ec..a4a5ae86 100644
--- a/src/internal/intscan.c
+++ b/src/internal/intscan.c
@@ -29,7 +29,7 @@ unsigned long long __intscan(FILE *f, unsigned base, int pok, unsigned long long
int c, neg=0;
unsigned x;
unsigned long long y;
- if (base > 36) {
+ if (base > 36 || base == 1) {
errno = EINVAL;
return 0;
}
--
2.11.0

View File

@ -0,0 +1,34 @@
From 27b3fd68f67b674440d21ea7ca5cf918d2e1559f Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Wed, 4 Jan 2017 22:54:06 -0500
Subject: [PATCH] fix crash from corrupted tls module list after failed dlopen
commit d56460c939c94a6c547abe8238f442b8de10bfbd introduced this
regression as part of splitting the tls module list out of the dso
list. the new code added to dlopen's failure path to undo the changes
adding the partially-loaded libraries reset the tls_tail pointer
correctly, but did not clear its link to the next list entry. thus, at
least until the next successful dlopen, the list was not terminated
but ended with an invalid next pointer, which __copy_tls attempted to
follow when a new thread was created.
patch by Mikael Vidstedt.
---
ldso/dynlink.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index c6890845..48dcd1c2 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1686,6 +1686,7 @@ void *dlopen(const char *file, int mode)
}
if (!orig_tls_tail) libc.tls_head = 0;
tls_tail = orig_tls_tail;
+ if (tls_tail) tls_tail->next = 0;
tls_cnt = orig_tls_cnt;
tls_offset = orig_tls_offset;
tls_align = orig_tls_align;
--
2.11.0

View File

@ -2,7 +2,7 @@
# Maintainer: Timo Teräs <timo.teras@iki.fi>
pkgname=musl
pkgver=1.1.16
pkgrel=1
pkgrel=2
pkgdesc="the musl c library (libc) implementation"
url="http://www.musl-libc.org/"
arch="all"
@ -15,6 +15,10 @@ subpackages="$pkgname-dev $pkgname-dbg libc6-compat:compat:noarch"
source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz
0001-fix-strftime-y-for-negative-years.patch
0002-make-globfree-safe-after-failed-glob-from-over-lengt.patch
0003-reduce-impact-of-REG_-namespace-pollution-in-x86-_64.patch
0004-fix-getopt-_long-clobbering-of-optopt-on-success.patch
0005-treat-base-1-as-an-error-in-strtol-family-functions.patch
0006-fix-crash-from-corrupted-tls-module-list-after-faile.patch
ldconfig
__stack_chk_fail_local.c
@ -129,6 +133,10 @@ compat() {
md5sums="ac52ccaec6b06ab0f289d37e8436859b musl-1.1.16.tar.gz
d9da36992a9ccd200242b38b67823b95 0001-fix-strftime-y-for-negative-years.patch
93a7dfa98dff324f2242d10f7c2d68f8 0002-make-globfree-safe-after-failed-glob-from-over-lengt.patch
3002db70e8282b7fb7c53052c5661275 0003-reduce-impact-of-REG_-namespace-pollution-in-x86-_64.patch
d83f0cf762aa4cb276138ee8a1a1f2f4 0004-fix-getopt-_long-clobbering-of-optopt-on-success.patch
1f525f2c2cf7da24c5c5ca327f791d3b 0005-treat-base-1-as-an-error-in-strtol-family-functions.patch
83f8f9baf934c4cb7d69c3799b0ca1dd 0006-fix-crash-from-corrupted-tls-module-list-after-faile.patch
830d01f7821b978df770b06db3790921 ldconfig
0df687757221bbb0fc1aa67f1bd646f9 __stack_chk_fail_local.c
57ef2c63b9ec6a2041694ace97d4ffa2 getconf.c
@ -137,6 +145,10 @@ eadc8794eadb79dbc383b2b91a32084d getent.c
sha256sums="937185a5e5d721050306cf106507a006c3f1f86d86cd550024ea7be909071011 musl-1.1.16.tar.gz
ec5209fe48aa54a859cc034557b7cca8307adaf345b3f7c061e0b284eee00ccc 0001-fix-strftime-y-for-negative-years.patch
b8c92e4c6c60b67fde4eab3465041c12a942a319501710babaf3b6ead381bd95 0002-make-globfree-safe-after-failed-glob-from-over-lengt.patch
521f02391536e2879359469a78afe10165b2ebd2467d841c65222d53f7e2a8e0 0003-reduce-impact-of-REG_-namespace-pollution-in-x86-_64.patch
2594a34dd18eab6130b8486e58bf3a5fd16e67692134edde3690ba35f2801db3 0004-fix-getopt-_long-clobbering-of-optopt-on-success.patch
0b9b5a37902dee6d53110e61f8fbada8673094dbcc5c43b5dc050652f10e558a 0005-treat-base-1-as-an-error-in-strtol-family-functions.patch
93b3a03017cf01439b88c7555d468898e2ea372bd2a9e1e3fd91f8f7f061f3d2 0006-fix-crash-from-corrupted-tls-module-list-after-faile.patch
b4a2c06db38742e8c42c3c9838b285a7d8cdac6c091ff3df5ff9a15f1e41b9c7 ldconfig
299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da __stack_chk_fail_local.c
d87d0cbb3690ae2c5d8cc218349fd8278b93855dd625deaf7ae50e320aad247c getconf.c
@ -145,6 +157,10 @@ f79a2930a2e5bb0624321589edf8b889d1e9b603e01e6b7ae214616605b3fdd7 iconv.c"
sha512sums="47c00e50b7605102fb4aebe1f9ba9db94d26fac64805f6d744c9c557a05b8a58dff7f9558ff7c8d66b5d7c43740cdc2dd79448bacac47f1414e6ada99c210140 musl-1.1.16.tar.gz
74e95ab3a74513e7a0513e004c376d4055eca0e21162e717dfcab249302a9060d3ac3eb88b562dea14b71b475b4dd2f703e355e2f5050b58891a848c5093c5f6 0001-fix-strftime-y-for-negative-years.patch
04805970e7dc11f84a86df49688f3b7670933860192e99637e189494c261e49b3cce1d80019d69341452062df03d5a349450015076c947296ac4a0d40e5789f4 0002-make-globfree-safe-after-failed-glob-from-over-lengt.patch
61a4f48055aa88cb5f40dd1ea9cc032e372896d7be530f25f17edba3d01706c233bf58a79bddf8952fb6b5d1481f04fac6dd619f4609251874f5a2e1f668f4a0 0003-reduce-impact-of-REG_-namespace-pollution-in-x86-_64.patch
ea103de2721926111510116dedb10e2320715fd20563a342c1dd30f3d1e68049990924b2cf4d03fd9d481ae9488f0e49da5373a79bcec4a8d8c357c64a24751b 0004-fix-getopt-_long-clobbering-of-optopt-on-success.patch
df96c4bd5ff9c197c8aa599948b69716587837de0f298d3adec56077b073e71a49a3c3345e0508cf8a4ed636e3171495bbbdc35435bd8e343c546436f6348359 0005-treat-base-1-as-an-error-in-strtol-family-functions.patch
4dc5cdcab11dee6b62fcb81401a816341e1d802a99e46b072c51575a2c25933354540fe22ae06dcdc85eb9a3cbf7256e7c43aab0e75843846551f9e18bfc39c2 0006-fix-crash-from-corrupted-tls-module-list-after-faile.patch
8d3a2d5315fc56fee7da9abb8b89bb38c6046c33d154c10d168fb35bfde6b0cf9f13042a3bceee34daf091bc409d699223735dcf19f382eeee1f6be34154f26f ldconfig
062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c
0d80f37b34a35e3d14b012257c50862dfeb9d2c81139ea2dfa101d981d093b009b9fa450ba27a708ac59377a48626971dfc58e20a3799084a65777a0c32cbc7d getconf.c