aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2016-10-19 09:49:32 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2016-10-19 11:57:07 +0200
commit68e061ff7e1af9183d3fe18a7992c4e82d06d1b6 (patch)
treef7720fcf74ae5bc697e6f965501eeb1b6139c8b1
parent75fc21729969f5ee39b47bd07b3c76b9c4d08d6d (diff)
downloadalpine_aports-68e061ff7e1af9183d3fe18a7992c4e82d06d1b6.tar.bz2
alpine_aports-68e061ff7e1af9183d3fe18a7992c4e82d06d1b6.tar.xz
alpine_aports-68e061ff7e1af9183d3fe18a7992c4e82d06d1b6.zip
main/musl: fix missing int overflow checks in regex
-rw-r--r--main/musl/0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch73
-rw-r--r--main/musl/APKBUILD6
2 files changed, 78 insertions, 1 deletions
diff --git a/main/musl/0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch b/main/musl/0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch
new file mode 100644
index 0000000000..2b8316c389
--- /dev/null
+++ b/main/musl/0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch
@@ -0,0 +1,73 @@
1From c3edc06d1e1360f3570db9155d6b318ae0d0f0f7 Mon Sep 17 00:00:00 2001
2From: Rich Felker <dalias@aerifal.cx>
3Date: Thu, 6 Oct 2016 18:34:58 -0400
4Subject: [PATCH] fix missing integer overflow checks in regexec buffer size
5 computations
6
7most of the possible overflows were already ruled out in practice by
8regcomp having already succeeded performing larger allocations.
9however at least the num_states*num_tags multiplication can clearly
10overflow in practice. for safety, check them all, and use the proper
11type, size_t, rather than int.
12
13also improve comments, use calloc in place of malloc+memset, and
14remove bogus casts.
15---
16 src/regex/regexec.c | 23 ++++++++++++++++++-----
17 1 file changed, 18 insertions(+), 5 deletions(-)
18
19diff --git a/src/regex/regexec.c b/src/regex/regexec.c
20index 16c5d0a..dd52319 100644
21--- a/src/regex/regexec.c
22+++ b/src/regex/regexec.c
23@@ -34,6 +34,7 @@
24 #include <wchar.h>
25 #include <wctype.h>
26 #include <limits.h>
27+#include <stdint.h>
28
29 #include <regex.h>
30
31@@ -206,11 +207,24 @@ tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string,
32
33 /* Allocate memory for temporary data required for matching. This needs to
34 be done for every matching operation to be thread safe. This allocates
35- everything in a single large block from the stack frame using alloca()
36- or with malloc() if alloca is unavailable. */
37+ everything in a single large block with calloc(). */
38 {
39- int tbytes, rbytes, pbytes, xbytes, total_bytes;
40+ size_t tbytes, rbytes, pbytes, xbytes, total_bytes;
41 char *tmp_buf;
42+
43+ /* Ensure that tbytes and xbytes*num_states cannot overflow, and that
44+ * they don't contribute more than 1/8 of SIZE_MAX to total_bytes. */
45+ if (num_tags > SIZE_MAX/(8 * sizeof(int) * tnfa->num_states))
46+ goto error_exit;
47+
48+ /* Likewise check rbytes. */
49+ if (tnfa->num_states+1 > SIZE_MAX/(8 * sizeof(*reach_next)))
50+ goto error_exit;
51+
52+ /* Likewise check pbytes. */
53+ if (tnfa->num_states > SIZE_MAX/(8 * sizeof(*reach_pos)))
54+ goto error_exit;
55+
56 /* Compute the length of the block we need. */
57 tbytes = sizeof(*tmp_tags) * num_tags;
58 rbytes = sizeof(*reach_next) * (tnfa->num_states + 1);
59@@ -221,10 +235,9 @@ tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string,
60 + (rbytes + xbytes * tnfa->num_states) * 2 + tbytes + pbytes;
61
62 /* Allocate the memory. */
63- buf = xmalloc((unsigned)total_bytes);
64+ buf = calloc(total_bytes, 1);
65 if (buf == NULL)
66 return REG_ESPACE;
67- memset(buf, 0, (size_t)total_bytes);
68
69 /* Get the various pointers within tmp_buf (properly aligned). */
70 tmp_tags = (void *)buf;
71--
722.10.0
73
diff --git a/main/musl/APKBUILD b/main/musl/APKBUILD
index 02c68e4832..ce86b09baa 100644
--- a/main/musl/APKBUILD
+++ b/main/musl/APKBUILD
@@ -2,7 +2,7 @@
2# Maintainer: Timo Teräs <timo.teras@iki.fi> 2# Maintainer: Timo Teräs <timo.teras@iki.fi>
3pkgname=musl 3pkgname=musl
4pkgver=1.1.14 4pkgver=1.1.14
5pkgrel=12 5pkgrel=13
6pkgdesc="the musl c library (libc) implementation" 6pkgdesc="the musl c library (libc) implementation"
7url="http://www.musl-libc.org/" 7url="http://www.musl-libc.org/"
8arch="all" 8arch="all"
@@ -34,6 +34,7 @@ source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz
34 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch 34 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch
35 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch 35 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch
36 0001-use-dynamic-buffer-for-getmntent.patch 36 0001-use-dynamic-buffer-for-getmntent.patch
37 0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch
37 38
38 ldconfig 39 ldconfig
39 __stack_chk_fail_local.c 40 __stack_chk_fail_local.c
@@ -163,6 +164,7 @@ f34ce9786c13ae945a4dff0c6f3436af 0018-in-performing-dns-lookups-check-result-fr
163252d72f8100f0661e7f335da4ac195e6 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch 164252d72f8100f0661e7f335da4ac195e6 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch
164c08825383e41e5dbcd3ffdfd2062dd47 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch 165c08825383e41e5dbcd3ffdfd2062dd47 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch
165c6b8732eea4642112c56f45ff00e356a 0001-use-dynamic-buffer-for-getmntent.patch 166c6b8732eea4642112c56f45ff00e356a 0001-use-dynamic-buffer-for-getmntent.patch
167fe6de41e930775994f64b772f1fdc45c 0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch
166830d01f7821b978df770b06db3790921 ldconfig 168830d01f7821b978df770b06db3790921 ldconfig
1670df687757221bbb0fc1aa67f1bd646f9 __stack_chk_fail_local.c 1690df687757221bbb0fc1aa67f1bd646f9 __stack_chk_fail_local.c
16857ef2c63b9ec6a2041694ace97d4ffa2 getconf.c 17057ef2c63b9ec6a2041694ace97d4ffa2 getconf.c
@@ -191,6 +193,7 @@ da4935744d9d6b60f06a9e6af9badd3c239d13cba204c9a10007b23fd10d6275 0017-fix-misal
19103c776222b65ab374c8659d61f905a9618c460994d70bb9b80655ba6a668c1d4 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch 19303c776222b65ab374c8659d61f905a9618c460994d70bb9b80655ba6a668c1d4 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch
192d157100aeed5b0866eb6d50288f63f26ea9900f1d4c7b8a1492294c912b5cc19 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch 194d157100aeed5b0866eb6d50288f63f26ea9900f1d4c7b8a1492294c912b5cc19 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch
193e1671e2436954f2eec0d2f49dd53e9e66ff0106c9c017a7ff69d35bdb7051055 0001-use-dynamic-buffer-for-getmntent.patch 195e1671e2436954f2eec0d2f49dd53e9e66ff0106c9c017a7ff69d35bdb7051055 0001-use-dynamic-buffer-for-getmntent.patch
196cec3fdd3a90f153a2c5a5d22ffd7429c14ecb105259a9c2540e46db6cfe71b55 0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch
194b4a2c06db38742e8c42c3c9838b285a7d8cdac6c091ff3df5ff9a15f1e41b9c7 ldconfig 197b4a2c06db38742e8c42c3c9838b285a7d8cdac6c091ff3df5ff9a15f1e41b9c7 ldconfig
195299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da __stack_chk_fail_local.c 198299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da __stack_chk_fail_local.c
196d87d0cbb3690ae2c5d8cc218349fd8278b93855dd625deaf7ae50e320aad247c getconf.c 199d87d0cbb3690ae2c5d8cc218349fd8278b93855dd625deaf7ae50e320aad247c getconf.c
@@ -219,6 +222,7 @@ a497943a0bc3752027467e21988e402eeab9ad2a7f37bc43cdbd05f6b45677e9cc72a200143f0b4f
219b8c50dbb33fa9cd8ae40b97f9662bedfc6fce4272e1e34b11daf14847b99e9a2bdc2dd9916329c0a407945e21d0070e8306e3ed2d1f857fc83ca64d430e4623a 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch 222b8c50dbb33fa9cd8ae40b97f9662bedfc6fce4272e1e34b11daf14847b99e9a2bdc2dd9916329c0a407945e21d0070e8306e3ed2d1f857fc83ca64d430e4623a 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch
2201a74d5f5e0f6f2fe6029ed0f18b4603f80c990f19aa13d83c5d1f40f032b2ffb3819aae13ae1f96415bb08571774eec164e71d09028f2a5db4ae9b77e48cafe7 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch 2231a74d5f5e0f6f2fe6029ed0f18b4603f80c990f19aa13d83c5d1f40f032b2ffb3819aae13ae1f96415bb08571774eec164e71d09028f2a5db4ae9b77e48cafe7 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch
221a25ff6c640fed110c124f2b12920111befa832202b906649e1d21613dda32b55bada0d59b310f4af2d4ae27c9ce2c92079ba1c919b4898c002f271c7a0c04878 0001-use-dynamic-buffer-for-getmntent.patch 224a25ff6c640fed110c124f2b12920111befa832202b906649e1d21613dda32b55bada0d59b310f4af2d4ae27c9ce2c92079ba1c919b4898c002f271c7a0c04878 0001-use-dynamic-buffer-for-getmntent.patch
2256376167c67fdd22c0c4476fc38ff89ae3ce46435f72d7c506460944dd8f7d9153eed9696738dff5b320f09b474964f2a57394530eb40197ad58a6956e87e68ff 0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch
2228d3a2d5315fc56fee7da9abb8b89bb38c6046c33d154c10d168fb35bfde6b0cf9f13042a3bceee34daf091bc409d699223735dcf19f382eeee1f6be34154f26f ldconfig 2268d3a2d5315fc56fee7da9abb8b89bb38c6046c33d154c10d168fb35bfde6b0cf9f13042a3bceee34daf091bc409d699223735dcf19f382eeee1f6be34154f26f ldconfig
223062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c 227062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c
2240d80f37b34a35e3d14b012257c50862dfeb9d2c81139ea2dfa101d981d093b009b9fa450ba27a708ac59377a48626971dfc58e20a3799084a65777a0c32cbc7d getconf.c 2280d80f37b34a35e3d14b012257c50862dfeb9d2c81139ea2dfa101d981d093b009b9fa450ba27a708ac59377a48626971dfc58e20a3799084a65777a0c32cbc7d getconf.c