aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2017-02-02 02:47:07 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2017-02-02 02:47:48 +0000
commitb85737558321bcd78e70cfed6309451a383798b1 (patch)
treed8a15bc477299d095866867db7c457421b36e681
parenta50d778d4aa38f21574f5af3ab0c8d2ec569706d (diff)
downloadaports-b85737558321bcd78e70cfed6309451a383798b1.tar.bz2
aports-b85737558321bcd78e70cfed6309451a383798b1.tar.xz
main/sed: fix random crashing caused by newlines (GNU bug #25390)
-rw-r--r--main/sed/APKBUILD14
-rw-r--r--main/sed/fix-reallocation-bug-when-matching-newlines.patch160
2 files changed, 169 insertions, 5 deletions
diff --git a/main/sed/APKBUILD b/main/sed/APKBUILD
index ee68bfb4a3..45187e0d31 100644
--- a/main/sed/APKBUILD
+++ b/main/sed/APKBUILD
@@ -1,7 +1,7 @@
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=sed
pkgver=4.3
-pkgrel=0
+pkgrel=1
subpackages="$pkgname-doc"
pkgdesc="GNU stream editor"
url="http://www.gnu.org/software/sed"
@@ -9,7 +9,8 @@ arch="all"
license="GPL"
makedepends="perl"
install="$pkgname.post-deinstall"
-source="ftp://ftp.gnu.org/pub/gnu/$pkgname/$pkgname-$pkgver.tar.xz"
+source="ftp://ftp.gnu.org/pub/gnu/$pkgname/$pkgname-$pkgver.tar.xz
+ fix-reallocation-bug-when-matching-newlines.patch"
builddir="$srcdir/$pkgname-$pkgver"
@@ -38,6 +39,9 @@ package() {
return 0
}
-md5sums="1957fe58dffa4a4106c1f1d7cc8dee18 sed-4.3.tar.xz"
-sha256sums="47c20d8841ce9e7b6ef8037768aac44bc2937fff1c265b291c824004d56bd0aa sed-4.3.tar.xz"
-sha512sums="4d76a099cf7115763b79b45be5c96338750baa47e34c36075f714e022614397aa9240099d6d009e69aa4d06b6cfc14dcc0f8313442a1465f448b36fb6874a26d sed-4.3.tar.xz"
+md5sums="1957fe58dffa4a4106c1f1d7cc8dee18 sed-4.3.tar.xz
+281083d69fbdff0fc9f22e3056bb6eda fix-reallocation-bug-when-matching-newlines.patch"
+sha256sums="47c20d8841ce9e7b6ef8037768aac44bc2937fff1c265b291c824004d56bd0aa sed-4.3.tar.xz
+e8287c052fb36c900cd0bffbe7447563165ed2d4972b02a036adbc6db73e70c3 fix-reallocation-bug-when-matching-newlines.patch"
+sha512sums="4d76a099cf7115763b79b45be5c96338750baa47e34c36075f714e022614397aa9240099d6d009e69aa4d06b6cfc14dcc0f8313442a1465f448b36fb6874a26d sed-4.3.tar.xz
+82cef9dacb65997877908c4f20f16d79a5dddd0c6965434a62bc0738be58466a5d278f8053f1027cd976d0395825cbe44dbf398153d950d2a43a3e2e66e46fea fix-reallocation-bug-when-matching-newlines.patch"
diff --git a/main/sed/fix-reallocation-bug-when-matching-newlines.patch b/main/sed/fix-reallocation-bug-when-matching-newlines.patch
new file mode 100644
index 0000000000..fa8df0e830
--- /dev/null
+++ b/main/sed/fix-reallocation-bug-when-matching-newlines.patch
@@ -0,0 +1,160 @@
+--- sed-4.3.orig/lib/dfa.c
++++ sed-4.3/lib/dfa.c
+@@ -2581,6 +2581,41 @@
+ free (merged.elems);
+ }
+
++/* Make sure D's state arrays are large enough to hold NEW_STATE. */
++static void
++realloc_trans_if_necessary (struct dfa *d, state_num new_state)
++{
++ state_num oldalloc = d->tralloc;
++ if (oldalloc <= new_state)
++ {
++ state_num **realtrans = d->trans ? d->trans - 2 : NULL;
++ ptrdiff_t newalloc, newalloc1;
++ newalloc1 = realtrans ? d->tralloc + 2 : 0;
++ realtrans = xpalloc (realtrans, &newalloc1, new_state - oldalloc + 1,
++ -1, sizeof *realtrans);
++ realtrans[0] = realtrans[1] = NULL;
++ d->trans = realtrans + 2;
++ d->tralloc = newalloc = newalloc1 - 2;
++ d->fails = xnrealloc (d->fails, newalloc, sizeof *d->fails);
++ d->success = xnrealloc (d->success, newalloc, sizeof *d->success);
++ d->newlines = xnrealloc (d->newlines, newalloc, sizeof *d->newlines);
++ if (d->localeinfo.multibyte)
++ {
++ realtrans = d->mb_trans ? d->mb_trans - 2 : NULL;
++ realtrans = xnrealloc (realtrans, newalloc1, sizeof *realtrans);
++ if (oldalloc == 0)
++ realtrans[0] = realtrans[1] = NULL;
++ d->mb_trans = realtrans + 2;
++ }
++ for (; oldalloc < newalloc; oldalloc++)
++ {
++ d->trans[oldalloc] = NULL;
++ d->fails[oldalloc] = NULL;
++ if (d->localeinfo.multibyte)
++ d->mb_trans[oldalloc] = NULL;
++ }
++ }
++}
+
+ /* Return the transition out of state s of d for the input character uc,
+ updating the slots in trans accordingly.
+@@ -2622,6 +2657,7 @@
+ state_num state; /* New state. */
+ state_num state_newline; /* New state on a newline transition. */
+ state_num state_letter; /* New state on a letter transition. */
++ state_num maxstate = -1;
+ size_t i, j, k;
+
+ #ifdef DEBUG
+@@ -2815,18 +2851,22 @@
+ /* Set the transitions for each character in the label. */
+ for (i = 0; i < NOTCHAR; i++)
+ if (tstbit (i, label))
+- switch (d->syntax.sbit[i])
+- {
+- case CTX_NEWLINE:
+- trans[i] = state_newline;
+- break;
+- case CTX_LETTER:
+- trans[i] = state_letter;
+- break;
+- default:
+- trans[i] = state;
+- break;
+- }
++ {
++ switch (d->syntax.sbit[i])
++ {
++ case CTX_NEWLINE:
++ trans[i] = state_newline;
++ break;
++ case CTX_LETTER:
++ trans[i] = state_letter;
++ break;
++ default:
++ trans[i] = state;
++ break;
++ }
++ if (maxstate < trans[i])
++ maxstate = trans[i];
++ }
+
+ #ifdef DEBUG
+ fprintf (stderr, "trans table %td", s);
+@@ -2843,6 +2883,9 @@
+ free (follows.elems);
+ free (tmp.elems);
+
++ /* Reallocate now, to allocate any newline transition properly. */
++ realloc_trans_if_necessary (d, maxstate);
++
+ /* Keep the newline transition in a special place so we can use it as
+ a sentinel. */
+ if (tstbit (d->syntax.eolbyte, label))
+@@ -2854,42 +2897,6 @@
+ return trans[uc];
+ }
+
+-/* Make sure D's state arrays are large enough to hold NEW_STATE. */
+-static void
+-realloc_trans_if_necessary (struct dfa *d, state_num new_state)
+-{
+- state_num oldalloc = d->tralloc;
+- if (oldalloc <= new_state)
+- {
+- state_num **realtrans = d->trans ? d->trans - 2 : NULL;
+- ptrdiff_t newalloc, newalloc1;
+- newalloc1 = realtrans ? d->tralloc + 2 : 0;
+- realtrans = xpalloc (realtrans, &newalloc1, new_state - oldalloc + 1,
+- -1, sizeof *realtrans);
+- realtrans[0] = realtrans[1] = NULL;
+- d->trans = realtrans + 2;
+- d->tralloc = newalloc = newalloc1 - 2;
+- d->fails = xnrealloc (d->fails, newalloc, sizeof *d->fails);
+- d->success = xnrealloc (d->success, newalloc, sizeof *d->success);
+- d->newlines = xnrealloc (d->newlines, newalloc, sizeof *d->newlines);
+- if (d->localeinfo.multibyte)
+- {
+- realtrans = d->mb_trans ? d->mb_trans - 2 : NULL;
+- realtrans = xnrealloc (realtrans, newalloc1, sizeof *realtrans);
+- if (oldalloc == 0)
+- realtrans[0] = realtrans[1] = NULL;
+- d->mb_trans = realtrans + 2;
+- }
+- for (; oldalloc < newalloc; oldalloc++)
+- {
+- d->trans[oldalloc] = NULL;
+- d->fails[oldalloc] = NULL;
+- if (d->localeinfo.multibyte)
+- d->mb_trans[oldalloc] = NULL;
+- }
+- }
+-}
+-
+ /* Calculate the transition table for a new state derived from state s
+ for a compiled dfa d after input character uc, and return the new
+ state number. */
+@@ -2936,18 +2943,7 @@
+ if (ACCEPTS_IN_CONTEXT (d->states[s].context, CTX_NONE, s, *d))
+ d->success[s] |= CTX_NONE;
+
+- s = dfastate (s, d, uc, trans);
+-
+- /* Now go through the new transition table, and make sure that the trans
+- and fail arrays are allocated large enough to hold a pointer for the
+- largest state mentioned in the table. */
+- state_num maxstate = -1;
+- for (int i = 0; i < NOTCHAR; i++)
+- if (maxstate < trans[i])
+- maxstate = trans[i];
+- realloc_trans_if_necessary (d, maxstate);
+-
+- return s;
++ return dfastate (s, d, uc, trans);
+ }
+
+ /* Multibyte character handling sub-routines for dfaexec. */