Gentoo Archives: gentoo-commits

From: Lars Wendler <polynomial-c@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: app-shells/bash/, app-shells/bash/files/
Date: Wed, 20 Mar 2019 18:25:20
Message-Id: 1553106308.94f68f9a36e6771e06bc39ad0286121e8956121c.polynomial-c@gentoo
1 commit: 94f68f9a36e6771e06bc39ad0286121e8956121c
2 Author: Lars Wendler <polynomial-c <AT> gentoo <DOT> org>
3 AuthorDate: Wed Mar 20 18:24:48 2019 +0000
4 Commit: Lars Wendler <polynomial-c <AT> gentoo <DOT> org>
5 CommitDate: Wed Mar 20 18:25:08 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=94f68f9a
7
8 app-shells/bash: Attempt to fix variable scoping in POSIX mode.
9
10 Bug: https://bugs.gentoo.org/676344
11 Package-Manager: Portage-2.3.62, Repoman-2.3.12
12 Signed-off-by: Lars Wendler <polynomial-c <AT> gentoo.org>
13
14 app-shells/bash/bash-5.0_p3-r1.ebuild | 267 +++++++++++++++++++++
15 .../bash-5.0-assignment-preceding-builtin.patch | 83 +++++++
16 2 files changed, 350 insertions(+)
17
18 diff --git a/app-shells/bash/bash-5.0_p3-r1.ebuild b/app-shells/bash/bash-5.0_p3-r1.ebuild
19 new file mode 100644
20 index 00000000000..d13f22168a6
21 --- /dev/null
22 +++ b/app-shells/bash/bash-5.0_p3-r1.ebuild
23 @@ -0,0 +1,267 @@
24 +# Copyright 1999-2019 Gentoo Authors
25 +# Distributed under the terms of the GNU General Public License v2
26 +
27 +EAPI=6
28 +
29 +inherit flag-o-matic toolchain-funcs multilib prefix
30 +
31 +# Official patchlevel
32 +# See ftp://ftp.cwru.edu/pub/bash/bash-5.0-patches/
33 +PLEVEL=${PV##*_p}
34 +MY_PV=${PV/_p*}
35 +MY_PV=${MY_PV/_/-}
36 +MY_P=${PN}-${MY_PV}
37 +is_release() {
38 + case ${PV} in
39 + *_alpha*|*_beta*|*_rc*) return 1 ;;
40 + *) return 0 ;;
41 + esac
42 +}
43 +[[ ${PV} != *_p* ]] && PLEVEL=0
44 +patches() {
45 + local opt=$1 plevel=${2:-${PLEVEL}} pn=${3:-${PN}} pv=${4:-${MY_PV}}
46 + [[ ${plevel} -eq 0 ]] && return 1
47 + eval set -- {1..${plevel}}
48 + set -- $(printf "${pn}${pv/\.}-%03d " "$@")
49 + if [[ ${opt} == -s ]] ; then
50 + echo "${@/#/${DISTDIR}/}"
51 + else
52 + local u
53 + for u in ftp://ftp.cwru.edu/pub/bash mirror://gnu/${pn} ; do
54 + printf "${u}/${pn}-${pv}-patches/%s " "$@"
55 + done
56 + fi
57 +}
58 +
59 +# The version of readline this bash normally ships with.
60 +READLINE_VER="8.0"
61 +
62 +DESCRIPTION="The standard GNU Bourne again shell"
63 +HOMEPAGE="http://tiswww.case.edu/php/chet/bash/bashtop.html"
64 +if is_release ; then
65 + SRC_URI="mirror://gnu/bash/${MY_P}.tar.gz $(patches)"
66 +else
67 + SRC_URI="ftp://ftp.cwru.edu/pub/bash/${MY_P}.tar.gz"
68 +fi
69 +
70 +LICENSE="GPL-3"
71 +SLOT="0"
72 +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~ppc-aix ~x64-cygwin ~amd64-fbsd ~x86-fbsd ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
73 +IUSE="afs bashlogger examples mem-scramble +net nls plugins +readline"
74 +
75 +DEPEND="
76 + >=sys-libs/ncurses-5.2-r2:0=
77 + readline? ( >=sys-libs/readline-${READLINE_VER}:0= )
78 + nls? ( virtual/libintl )
79 +"
80 +RDEPEND="
81 + ${DEPEND}
82 + !<sys-apps/portage-2.1.6.7_p1
83 +"
84 +# we only need yacc when the .y files get patched (bash42-005)
85 +#DEPEND+=" virtual/yacc"
86 +
87 +S="${WORKDIR}/${MY_P}"
88 +
89 +PATCHES=(
90 + # Patches from Chet sent to bashbug ml
91 + "${FILESDIR}"/${PN}-5.0-history-zero-length.patch
92 + "${FILESDIR}"/${PN}-5.0-history-append.patch
93 + "${FILESDIR}"/${PN}-5.0-optimize-connection-fork.patch
94 + "${FILESDIR}"/${PN}-5.0-syslog-history-extern.patch
95 + "${FILESDIR}"/${PN}-5.0-assignment-preceding-builtin.patch
96 +)
97 +
98 +pkg_setup() {
99 + if is-flag -malign-double ; then #7332
100 + eerror "Detected bad CFLAGS '-malign-double'. Do not use this"
101 + eerror "as it breaks LFS (struct stat64) on x86."
102 + die "remove -malign-double from your CFLAGS mr ricer"
103 + fi
104 + if use bashlogger ; then
105 + ewarn "The logging patch should ONLY be used in restricted (i.e. honeypot) envs."
106 + ewarn "This will log ALL output you enter into the shell, you have been warned."
107 + fi
108 +}
109 +
110 +src_unpack() {
111 + unpack ${MY_P}.tar.gz
112 +}
113 +
114 +src_prepare() {
115 + # Include official patches
116 + [[ ${PLEVEL} -gt 0 ]] && eapply -p0 $(patches -s)
117 +
118 + # Clean out local libs so we know we use system ones w/releases.
119 + if is_release ; then
120 + rm -rf lib/{readline,termcap}/*
121 + touch lib/{readline,termcap}/Makefile.in # for config.status
122 + sed -ri -e 's:\$[(](RL|HIST)_LIBSRC[)]/[[:alpha:]]*.h::g' Makefile.in || die
123 + fi
124 +
125 + # Prefixify hardcoded path names. No-op for non-prefix.
126 + hprefixify pathnames.h.in
127 +
128 + # Avoid regenerating docs after patches #407985
129 + sed -i -r '/^(HS|RL)USER/s:=.*:=:' doc/Makefile.in || die
130 + touch -r . doc/*
131 +
132 + eapply -p0 "${PATCHES[@]}"
133 + eapply_user
134 +}
135 +
136 +src_configure() {
137 + local myconf=(
138 + --disable-profiling
139 + --docdir='$(datarootdir)'/doc/${PF}
140 + --htmldir='$(docdir)/html'
141 + --with-curses
142 + $(use_enable mem-scramble)
143 + $(use_enable net net-redirections)
144 + $(use_enable readline)
145 + $(use_enable readline bang-history)
146 + $(use_enable readline history)
147 + $(use_with afs)
148 + $(use_with mem-scramble bash-malloc)
149 + )
150 +
151 + # For descriptions of these, see config-top.h
152 + # bashrc/#26952 bash_logout/#90488 ssh/#24762 mktemp/#574426
153 + append-cppflags \
154 + -DDEFAULT_PATH_VALUE=\'\"${EPREFIX}/usr/local/sbin:${EPREFIX}/usr/local/bin:${EPREFIX}/usr/sbin:${EPREFIX}/usr/bin:${EPREFIX}/sbin:${EPREFIX}/bin\"\' \
155 + -DSTANDARD_UTILS_PATH=\'\"${EPREFIX}/bin:${EPREFIX}/usr/bin:${EPREFIX}/sbin:${EPREFIX}/usr/sbin\"\' \
156 + -DSYS_BASHRC=\'\"${EPREFIX}/etc/bash/bashrc\"\' \
157 + -DSYS_BASH_LOGOUT=\'\"${EPREFIX}/etc/bash/bash_logout\"\' \
158 + -DNON_INTERACTIVE_LOGIN_SHELLS \
159 + -DSSH_SOURCE_BASHRC \
160 + $(use bashlogger && echo -DSYSLOG_HISTORY)
161 +
162 + # Don't even think about building this statically without
163 + # reading Bug 7714 first. If you still build it statically,
164 + # don't come crying to us with bugs ;).
165 + #use static && export LDFLAGS="${LDFLAGS} -static"
166 + use nls || myconf+=( --disable-nls )
167 +
168 + # Historically, we always used the builtin readline, but since
169 + # our handling of SONAME upgrades has gotten much more stable
170 + # in the PM (and the readline ebuild itself preserves the old
171 + # libs during upgrades), linking against the system copy should
172 + # be safe.
173 + # Exact cached version here doesn't really matter as long as it
174 + # is at least what's in the DEPEND up above.
175 + export ac_cv_rl_version=${READLINE_VER%%_*}
176 +
177 + # Force linking with system curses ... the bundled termcap lib
178 + # sucks bad compared to ncurses. For the most part, ncurses
179 + # is here because readline needs it. But bash itself calls
180 + # ncurses in one or two small places :(.
181 +
182 + if is_release ; then
183 + # Use system readline only with released versions.
184 + myconf+=( --with-installed-readline=. )
185 + fi
186 +
187 + if use plugins; then
188 + append-ldflags -Wl,-rpath,/usr/$(get_libdir)/bash
189 + else
190 + # Disable the plugins logic by hand since bash doesn't
191 + # provide a way of doing it.
192 + export ac_cv_func_dl{close,open,sym}=no \
193 + ac_cv_lib_dl_dlopen=no ac_cv_header_dlfcn_h=no
194 + sed -i \
195 + -e '/LOCAL_LDFLAGS=/s:-rdynamic::' \
196 + configure || die
197 + fi
198 + tc-export AR #444070
199 + econf "${myconf[@]}"
200 +}
201 +
202 +src_compile() {
203 + emake
204 +
205 + if use plugins ; then
206 + emake -C examples/loadables all others
207 + fi
208 +}
209 +
210 +src_install() {
211 + local d f
212 +
213 + default
214 +
215 + dodir /bin
216 + mv "${ED%/}"/usr/bin/bash "${ED%/}"/bin/ || die
217 + dosym bash /bin/rbash
218 +
219 + insinto /etc/bash
220 + doins "${FILESDIR}"/bash_logout
221 + doins "$(prefixify_ro "${FILESDIR}"/bashrc)"
222 + keepdir /etc/bash/bashrc.d
223 + insinto /etc/skel
224 + for f in bash{_logout,_profile,rc} ; do
225 + newins "${FILESDIR}"/dot-${f} .${f}
226 + done
227 +
228 + local sed_args=(
229 + -e "s:#${USERLAND}#@::"
230 + -e '/#@/d'
231 + )
232 + if ! use readline ; then
233 + sed_args+=( #432338
234 + -e '/^shopt -s histappend/s:^:#:'
235 + -e 's:use_color=true:use_color=false:'
236 + )
237 + fi
238 + sed -i \
239 + "${sed_args[@]}" \
240 + "${ED%/}"/etc/skel/.bashrc \
241 + "${ED%/}"/etc/bash/bashrc || die
242 +
243 + if use plugins ; then
244 + exeinto /usr/$(get_libdir)/bash
245 + doexe $(echo examples/loadables/*.o | sed 's:\.o::g')
246 + insinto /usr/include/bash-plugins
247 + doins *.h builtins/*.h include/*.h lib/{glob/glob.h,tilde/tilde.h}
248 + fi
249 +
250 + if use examples ; then
251 + for d in examples/{functions,misc,scripts,startup-files} ; do
252 + exeinto /usr/share/doc/${PF}/${d}
253 + insinto /usr/share/doc/${PF}/${d}
254 + for f in ${d}/* ; do
255 + if [[ ${f##*/} != PERMISSION ]] && [[ ${f##*/} != *README ]] ; then
256 + doexe ${f}
257 + else
258 + doins ${f}
259 + fi
260 + done
261 + done
262 + fi
263 +
264 + doman doc/*.1
265 + newdoc CWRU/changelog ChangeLog
266 + dosym bash.info /usr/share/info/bashref.info
267 +}
268 +
269 +pkg_preinst() {
270 + if [[ -e ${EROOT}/etc/bashrc ]] && [[ ! -d ${EROOT}/etc/bash ]] ; then
271 + mkdir -p "${EROOT}"/etc/bash
272 + mv -f "${EROOT}"/etc/bashrc "${EROOT}"/etc/bash/
273 + fi
274 +
275 + if [[ -L ${EROOT}/bin/sh ]] ; then
276 + # rewrite the symlink to ensure that its mtime changes. having /bin/sh
277 + # missing even temporarily causes a fatal error with paludis.
278 + local target=$(readlink "${EROOT}"/bin/sh)
279 + local tmp=$(emktemp "${EROOT}"/bin)
280 + ln -sf "${target}" "${tmp}"
281 + mv -f "${tmp}" "${EROOT}"/bin/sh
282 + fi
283 +}
284 +
285 +pkg_postinst() {
286 + # If /bin/sh does not exist, provide it
287 + if [[ ! -e ${EROOT}/bin/sh ]] ; then
288 + ln -sf bash "${EROOT}"/bin/sh
289 + fi
290 +}
291
292 diff --git a/app-shells/bash/files/bash-5.0-assignment-preceding-builtin.patch b/app-shells/bash/files/bash-5.0-assignment-preceding-builtin.patch
293 new file mode 100644
294 index 00000000000..84b7fbc8b2a
295 --- /dev/null
296 +++ b/app-shells/bash/files/bash-5.0-assignment-preceding-builtin.patch
297 @@ -0,0 +1,83 @@
298 +*** ../bash-5.0-patched/variables.c 2018-12-18 11:07:21.000000000 -0500
299 +--- variables.c 2019-03-20 10:30:56.000000000 -0400
300 +***************
301 +*** 4473,4476 ****
302 +--- 4473,4489 ----
303 + var = (SHELL_VAR *)data;
304 +
305 ++ #if 1 /* TAG:bash-5.1 */
306 ++ /* Just like do_assignment_internal(). This makes assignments preceding
307 ++ special builtins act like standalone assignment statements when in
308 ++ posix mode, satisfying the posix requirement that this affect the
309 ++ "current execution environment." */
310 ++ v = bind_variable (var->name, value_cell (var), ASS_FORCE|ASS_NOLONGJMP);
311 ++
312 ++ /* If this modifies an existing local variable, v->context will be non-zero.
313 ++ If it comes back with v->context == 0, we bound at the global context.
314 ++ Set binding_table appropriately. It doesn't matter whether it's correct
315 ++ if the variable is local, only that it's not global_variables->table */
316 ++ binding_table = v->context ? shell_variables->table : global_variables->table;
317 ++ #else
318 + binding_table = global_variables->table;
319 + if (binding_table == 0)
320 +***************
321 +*** 4478,4486 ****
322 +
323 + v = bind_variable_internal (var->name, value_cell (var), binding_table, 0, ASS_FORCE|ASS_NOLONGJMP);
324 +
325 + /* global variables are no longer temporary and don't need propagating. */
326 +! var->attributes &= ~(att_tempvar|att_propagate);
327 + if (v)
328 +! v->attributes |= var->attributes;
329 +
330 + if (find_special_var (var->name) >= 0)
331 +--- 4491,4508 ----
332 +
333 + v = bind_variable_internal (var->name, value_cell (var), binding_table, 0, ASS_FORCE|ASS_NOLONGJMP);
334 ++ #endif
335 +
336 + /* global variables are no longer temporary and don't need propagating. */
337 +! if (binding_table == global_variables->table)
338 +! var->attributes &= ~(att_tempvar|att_propagate);
339 +!
340 + if (v)
341 +! {
342 +! v->attributes |= var->attributes;
343 +! v->attributes &= ~att_tempvar; /* not a temp var now */
344 +! #if 0 /* TAG:bash-5.1 code doesn't need this, disable for bash-5.1 */
345 +! v->context = (binding_table == global_variables->table) ? 0 : shell_variables->scope;
346 +! #endif
347 +! }
348 +
349 + if (find_special_var (var->name) >= 0)
350 +***************
351 +*** 4576,4587 ****
352 + {
353 + int i;
354 +
355 + tempvar_list = strvec_create (HASH_ENTRIES (temporary_env) + 1);
356 + tempvar_list[tvlist_ind = 0] = 0;
357 +!
358 +! hash_flush (temporary_env, pushf);
359 +! hash_dispose (temporary_env);
360 + temporary_env = (HASH_TABLE *)NULL;
361 +
362 + tempvar_list[tvlist_ind] = 0;
363 +
364 +--- 4598,4612 ----
365 + {
366 + int i;
367 ++ HASH_TABLE *disposer;
368 +
369 + tempvar_list = strvec_create (HASH_ENTRIES (temporary_env) + 1);
370 + tempvar_list[tvlist_ind = 0] = 0;
371 +!
372 +! disposer = temporary_env;
373 + temporary_env = (HASH_TABLE *)NULL;
374 +
375 ++ hash_flush (disposer, pushf);
376 ++ hash_dispose (disposer);
377 ++
378 + tempvar_list[tvlist_ind] = 0;
379 +
380 +