summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'sys-apps/nawk')
-rw-r--r--sys-apps/nawk/files/nawk-20230909-big-endian.patch51
-rw-r--r--sys-apps/nawk/nawk-20230909-r1.ebuild61
2 files changed, 112 insertions, 0 deletions
diff --git a/sys-apps/nawk/files/nawk-20230909-big-endian.patch b/sys-apps/nawk/files/nawk-20230909-big-endian.patch
new file mode 100644
index 000000000000..b39e7b4bee62
--- /dev/null
+++ b/sys-apps/nawk/files/nawk-20230909-big-endian.patch
@@ -0,0 +1,51 @@
+https://github.com/onetrueawk/awk/pull/196
+
+From 75c017ca09a70e14a862f7285cf91bb87ec1f443 Mon Sep 17 00:00:00 2001
+From: "Todd C. Miller" <Todd.Miller@sudo.ws>
+Date: Mon, 18 Sep 2023 17:34:34 -0600
+Subject: [PATCH 1/2] Fix a bad cast to char * that causes incorrect results on
+ big endian.
+
+Now that awk stores chars as int we need to cast the Node * to int *.
+--- a/b.c
++++ b/b.c
+@@ -527,7 +527,7 @@ int first(Node *p) /* collects initially active leaves of p into setvec */
+ setvec[lp] = 1;
+ setcnt++;
+ }
+- if (type(p) == CCL && (*(char *) right(p)) == '\0')
++ if (type(p) == CCL && (*(int *) right(p)) == 0)
+ return(0); /* empty CCL */
+ return(1);
+ case PLUS:
+
+From 0048c96e94c732c6fb2ebe50eeb3450c1672fe0f Mon Sep 17 00:00:00 2001
+From: "Todd C. Miller" <Todd.Miller@sudo.ws>
+Date: Thu, 21 Sep 2023 11:20:16 -0600
+Subject: [PATCH 2/2] Use cclenter("") to construct an empty CCL, not
+ tostring("").
+
+We need to store a UTF-32 string, not a UTF-8 string, for consistency
+with the other CCL code. Fixes an out-of-bounds read of an empty
+CCL.
+--- a/b.c
++++ b/b.c
+@@ -945,7 +945,7 @@ Node *primary(void)
+ rtok = relex();
+ if (rtok == ')') { /* special pleading for () */
+ rtok = relex();
+- return unary(op2(CCL, NIL, (Node *) tostring("")));
++ return unary(op2(CCL, NIL, (Node *) cclenter("")));
+ }
+ np = regexp();
+ if (rtok == ')') {
+@@ -968,7 +968,7 @@ Node *concat(Node *np)
+ return (concat(op2(CAT, np, primary())));
+ case EMPTYRE:
+ rtok = relex();
+- return (concat(op2(CAT, op2(CCL, NIL, (Node *) tostring("")),
++ return (concat(op2(CAT, op2(CCL, NIL, (Node *) cclenter("")),
+ primary())));
+ }
+ return (np);
+
diff --git a/sys-apps/nawk/nawk-20230909-r1.ebuild b/sys-apps/nawk/nawk-20230909-r1.ebuild
new file mode 100644
index 000000000000..aa037df95f05
--- /dev/null
+++ b/sys-apps/nawk/nawk-20230909-r1.ebuild
@@ -0,0 +1,61 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+inherit toolchain-funcs
+
+DESCRIPTION="Brian Kernighan's pattern scanning and processing language"
+HOMEPAGE="https://www.cs.princeton.edu/~bwk/btl.mirror/"
+SRC_URI="https://github.com/onetrueawk/awk/archive/${PV}.tar.gz -> ${P}.tar.gz"
+S="${WORKDIR}/awk-${PV}"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux"
+
+BDEPEND="
+ app-alternatives/yacc
+"
+
+DOCS=( README.md FIXES )
+
+PATCHES=(
+ "${FILESDIR}"/${PN}-20230909-big-endian.patch
+)
+
+src_compile() {
+ emake \
+ CC="$(tc-getCC)" \
+ HOSTCC="$(tc-getBUILD_CC)" \
+ CFLAGS="${CFLAGS}" \
+ CPPFLAGS="${CPPFLAGS} -DHAS_ISBLANK" \
+ ALLOC="${LDFLAGS}" \
+ YACC=$(type -p yacc) \
+ YFLAGS="-d -b awkgram"
+}
+
+src_install() {
+ newbin a.out "${PN}"
+ sed \
+ -e 's/awk/nawk/g' \
+ -e 's/AWK/NAWK/g' \
+ -e 's/Awk/Nawk/g' \
+ awk.1 > "${PN}".1 || die "manpage patch failed"
+ doman "${PN}.1"
+ einstalldocs
+}
+
+pkg_postinst() {
+ if has_version app-admin/eselect && has_version app-eselect/eselect-awk
+ then
+ eselect awk update ifunset
+ fi
+}
+
+pkg_postrm() {
+ if has_version app-admin/eselect && has_version app-eselect/eselect-awk
+ then
+ eselect awk update ifunset
+ fi
+}