diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2016-10-19 09:49:32 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2016-10-19 11:57:07 +0200 |
commit | 68e061ff7e1af9183d3fe18a7992c4e82d06d1b6 (patch) | |
tree | f7720fcf74ae5bc697e6f965501eeb1b6139c8b1 | |
parent | 75fc21729969f5ee39b47bd07b3c76b9c4d08d6d (diff) | |
download | alpine_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.patch | 73 | ||||
-rw-r--r-- | main/musl/APKBUILD | 6 |
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 @@ | |||
1 | From c3edc06d1e1360f3570db9155d6b318ae0d0f0f7 Mon Sep 17 00:00:00 2001 | ||
2 | From: Rich Felker <dalias@aerifal.cx> | ||
3 | Date: Thu, 6 Oct 2016 18:34:58 -0400 | ||
4 | Subject: [PATCH] fix missing integer overflow checks in regexec buffer size | ||
5 | computations | ||
6 | |||
7 | most of the possible overflows were already ruled out in practice by | ||
8 | regcomp having already succeeded performing larger allocations. | ||
9 | however at least the num_states*num_tags multiplication can clearly | ||
10 | overflow in practice. for safety, check them all, and use the proper | ||
11 | type, size_t, rather than int. | ||
12 | |||
13 | also improve comments, use calloc in place of malloc+memset, and | ||
14 | remove bogus casts. | ||
15 | --- | ||
16 | src/regex/regexec.c | 23 ++++++++++++++++++----- | ||
17 | 1 file changed, 18 insertions(+), 5 deletions(-) | ||
18 | |||
19 | diff --git a/src/regex/regexec.c b/src/regex/regexec.c | ||
20 | index 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 | -- | ||
72 | 2.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> |
3 | pkgname=musl | 3 | pkgname=musl |
4 | pkgver=1.1.14 | 4 | pkgver=1.1.14 |
5 | pkgrel=12 | 5 | pkgrel=13 |
6 | pkgdesc="the musl c library (libc) implementation" | 6 | pkgdesc="the musl c library (libc) implementation" |
7 | url="http://www.musl-libc.org/" | 7 | url="http://www.musl-libc.org/" |
8 | arch="all" | 8 | arch="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 | |||
163 | 252d72f8100f0661e7f335da4ac195e6 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch | 164 | 252d72f8100f0661e7f335da4ac195e6 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch |
164 | c08825383e41e5dbcd3ffdfd2062dd47 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch | 165 | c08825383e41e5dbcd3ffdfd2062dd47 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch |
165 | c6b8732eea4642112c56f45ff00e356a 0001-use-dynamic-buffer-for-getmntent.patch | 166 | c6b8732eea4642112c56f45ff00e356a 0001-use-dynamic-buffer-for-getmntent.patch |
167 | fe6de41e930775994f64b772f1fdc45c 0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch | ||
166 | 830d01f7821b978df770b06db3790921 ldconfig | 168 | 830d01f7821b978df770b06db3790921 ldconfig |
167 | 0df687757221bbb0fc1aa67f1bd646f9 __stack_chk_fail_local.c | 169 | 0df687757221bbb0fc1aa67f1bd646f9 __stack_chk_fail_local.c |
168 | 57ef2c63b9ec6a2041694ace97d4ffa2 getconf.c | 170 | 57ef2c63b9ec6a2041694ace97d4ffa2 getconf.c |
@@ -191,6 +193,7 @@ da4935744d9d6b60f06a9e6af9badd3c239d13cba204c9a10007b23fd10d6275 0017-fix-misal | |||
191 | 03c776222b65ab374c8659d61f905a9618c460994d70bb9b80655ba6a668c1d4 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch | 193 | 03c776222b65ab374c8659d61f905a9618c460994d70bb9b80655ba6a668c1d4 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch |
192 | d157100aeed5b0866eb6d50288f63f26ea9900f1d4c7b8a1492294c912b5cc19 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch | 194 | d157100aeed5b0866eb6d50288f63f26ea9900f1d4c7b8a1492294c912b5cc19 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch |
193 | e1671e2436954f2eec0d2f49dd53e9e66ff0106c9c017a7ff69d35bdb7051055 0001-use-dynamic-buffer-for-getmntent.patch | 195 | e1671e2436954f2eec0d2f49dd53e9e66ff0106c9c017a7ff69d35bdb7051055 0001-use-dynamic-buffer-for-getmntent.patch |
196 | cec3fdd3a90f153a2c5a5d22ffd7429c14ecb105259a9c2540e46db6cfe71b55 0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch | ||
194 | b4a2c06db38742e8c42c3c9838b285a7d8cdac6c091ff3df5ff9a15f1e41b9c7 ldconfig | 197 | b4a2c06db38742e8c42c3c9838b285a7d8cdac6c091ff3df5ff9a15f1e41b9c7 ldconfig |
195 | 299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da __stack_chk_fail_local.c | 198 | 299a7d75a09de3e2e11e7fb4acc3182e4a14e868093d2f30938fce9bfcff13da __stack_chk_fail_local.c |
196 | d87d0cbb3690ae2c5d8cc218349fd8278b93855dd625deaf7ae50e320aad247c getconf.c | 199 | d87d0cbb3690ae2c5d8cc218349fd8278b93855dd625deaf7ae50e320aad247c getconf.c |
@@ -219,6 +222,7 @@ a497943a0bc3752027467e21988e402eeab9ad2a7f37bc43cdbd05f6b45677e9cc72a200143f0b4f | |||
219 | b8c50dbb33fa9cd8ae40b97f9662bedfc6fce4272e1e34b11daf14847b99e9a2bdc2dd9916329c0a407945e21d0070e8306e3ed2d1f857fc83ca64d430e4623a 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch | 222 | b8c50dbb33fa9cd8ae40b97f9662bedfc6fce4272e1e34b11daf14847b99e9a2bdc2dd9916329c0a407945e21d0070e8306e3ed2d1f857fc83ca64d430e4623a 0020-improve-abort-fallback-behavior-when-raising-SIGABRT.patch |
220 | 1a74d5f5e0f6f2fe6029ed0f18b4603f80c990f19aa13d83c5d1f40f032b2ffb3819aae13ae1f96415bb08571774eec164e71d09028f2a5db4ae9b77e48cafe7 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch | 223 | 1a74d5f5e0f6f2fe6029ed0f18b4603f80c990f19aa13d83c5d1f40f032b2ffb3819aae13ae1f96415bb08571774eec164e71d09028f2a5db4ae9b77e48cafe7 0021-fix-asctime-day-month-names-not-to-vary-by-locale.patch |
221 | a25ff6c640fed110c124f2b12920111befa832202b906649e1d21613dda32b55bada0d59b310f4af2d4ae27c9ce2c92079ba1c919b4898c002f271c7a0c04878 0001-use-dynamic-buffer-for-getmntent.patch | 224 | a25ff6c640fed110c124f2b12920111befa832202b906649e1d21613dda32b55bada0d59b310f4af2d4ae27c9ce2c92079ba1c919b4898c002f271c7a0c04878 0001-use-dynamic-buffer-for-getmntent.patch |
225 | 6376167c67fdd22c0c4476fc38ff89ae3ce46435f72d7c506460944dd8f7d9153eed9696738dff5b320f09b474964f2a57394530eb40197ad58a6956e87e68ff 0001-fix-missing-integer-overflow-checks-in-regexec-buffe.patch | ||
222 | 8d3a2d5315fc56fee7da9abb8b89bb38c6046c33d154c10d168fb35bfde6b0cf9f13042a3bceee34daf091bc409d699223735dcf19f382eeee1f6be34154f26f ldconfig | 226 | 8d3a2d5315fc56fee7da9abb8b89bb38c6046c33d154c10d168fb35bfde6b0cf9f13042a3bceee34daf091bc409d699223735dcf19f382eeee1f6be34154f26f ldconfig |
223 | 062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c | 227 | 062bb49fa54839010acd4af113e20f7263dde1c8a2ca359b5fb2661ef9ed9d84a0f7c3bc10c25dcfa10bb3c5a4874588dff636ac43d5dbb3d748d75400756d0b __stack_chk_fail_local.c |
224 | 0d80f37b34a35e3d14b012257c50862dfeb9d2c81139ea2dfa101d981d093b009b9fa450ba27a708ac59377a48626971dfc58e20a3799084a65777a0c32cbc7d getconf.c | 228 | 0d80f37b34a35e3d14b012257c50862dfeb9d2c81139ea2dfa101d981d093b009b9fa450ba27a708ac59377a48626971dfc58e20a3799084a65777a0c32cbc7d getconf.c |