- fix crash when alias contains alias

- fix crash when xtrace is enabled
This commit is contained in:
Michal Hlavinka 2010-07-21 13:04:16 +00:00
parent e2f293dd3f
commit 5f11470f9a
3 changed files with 113 additions and 1 deletions

31
mksh-39c-dblalias.patch Normal file
View File

@ -0,0 +1,31 @@
--- a/check.t 2010/07/19 22:41:01 1.383
+++ b/check.t 2010/07/21 11:31:13 1.384
@@ -184,6 +184,17 @@ stdin:
expected-stdout:
tf
tf
+---
+name: alias-10
+description:
+ Check that recursion is detected/avoided in aliases.
+ Regression, introduced during an old bugfix.
+stdin:
+ alias foo='print hello '
+ alias bar='foo world'
+ echo $(bar)
+expected-stdout:
+ hello world
---
name: arith-lazy-1
description:
--- a/lex.c 2010/07/17 22:09:36 1.116
+++ b/lex.c 2010/07/21 11:31:15 1.117
@@ -1110,7 +1110,7 @@ yylex(int cf)
else {
Source *s = source;
- while (s->flags & SF_HASALIAS)
+ while (s && (s->flags & SF_HASALIAS))
if (s->u.tblp == p)
return (LWORD);
else

69
mksh-39c-fixsetx.patch Normal file
View File

@ -0,0 +1,69 @@
--- old/shf.c 2009/11/28 14:28:03 1.35
+++ new/shf.c 2010/07/19 22:41:04 1.36
@@ -636,32 +636,45 @@ shf_write(const char *buf, int nbytes, s
shf->wnleft -= ncopy;
}
if (nbytes > 0) {
- /* Flush deals with strings and sticky errors */
- if (shf_emptybuf(shf, EB_GROW) == EOF)
- return (EOF);
- if (nbytes > shf->wbsize) {
- ncopy = nbytes;
- if (shf->wbsize)
- ncopy -= nbytes % shf->wbsize;
- nbytes -= ncopy;
- while (ncopy > 0) {
- n = write(shf->fd, buf, ncopy);
- if (n < 0) {
- if (errno == EINTR &&
- !(shf->flags & SHF_INTERRUPT))
- continue;
- shf->flags |= SHF_ERROR;
- shf->errno_ = errno;
- shf->wnleft = 0;
- /* Note: fwrite(3S) returns 0 for
- * errors - this doesn't */
+ if (shf->flags & SHF_STRING) {
+ /* resize buffer until there's enough space left */
+ while (nbytes > shf->wnleft)
+ if (shf_emptybuf(shf, EB_GROW) == EOF)
return (EOF);
+ /* then write everything into the buffer */
+ } else {
+ /* flush deals with sticky errors */
+ if (shf_emptybuf(shf, EB_GROW) == EOF)
+ return (EOF);
+ /* write chunks larger than window size directly */
+ if (nbytes > shf->wbsize) {
+ ncopy = nbytes;
+ if (shf->wbsize)
+ ncopy -= nbytes % shf->wbsize;
+ nbytes -= ncopy;
+ while (ncopy > 0) {
+ n = write(shf->fd, buf, ncopy);
+ if (n < 0) {
+ if (errno == EINTR &&
+ !(shf->flags & SHF_INTERRUPT))
+ continue;
+ shf->flags |= SHF_ERROR;
+ shf->errno_ = errno;
+ shf->wnleft = 0;
+ /*
+ * Note: fwrite(3) returns 0
+ * for errors - this doesn't
+ */
+ return (EOF);
+ }
+ buf += n;
+ ncopy -= n;
}
- buf += n;
- ncopy -= n;
}
+ /* ... and buffer the rest */
}
if (nbytes > 0) {
+ /* write remaining bytes to buffer */
memcpy(shf->wp, buf, nbytes);
shf->wp += nbytes;
shf->wnleft -= nbytes;

View File

@ -3,13 +3,15 @@
Summary: MirBSD enhanced version of the Korn Shell
Name: mksh
Version: 39c
Release: 2%{?dist}
Release: 3%{?dist}
# BSD (setmode.c), ISC (strlcpy.c), MirOS (the rest)
License: MirOS and ISC and BSD
Group: System Environment/Shells
URL: http://www.mirbsd.de/%{name}.htm
Source0: http://www.mirbsd.org/MirOS/dist/mir/%{name}/%{name}-R%{version}.cpio.gz
Source1: dot-mkshrc
Patch1: mksh-39c-fixsetx.patch
Patch2: mksh-39c-dblalias.patch
Requires(post): grep
Requires(postun): sed
BuildRequires: util-linux, ed
@ -29,6 +31,12 @@ bourne shell replacement, pdksh successor and an alternative to the C shell.
gzip -dc %{SOURCE0} | cpio -imd
mv %{name}/* . && rm -rf %{name}
# from upstream cvs, for mksh < "R39 2010/07/19", rhbz#616771
%patch1 -p1 -b .fixsetx
# from upstream cvs, for mksh < "R39 2010/07/21", rhbz#616777
%patch2 -p1 -b .dblalias
%build
CFLAGS="$RPM_OPT_FLAGS" sh Build.sh -r -combine
@ -70,6 +78,10 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/%{name}.1*
%changelog
* Wed Jul 21 2010 Michal Hlavinka <mhlavink@redhat.com> 39c-3
- fix crash when alias contains alias
- fix crash when xtrace is enabled
* Sun Jul 11 2010 Robert Scheck <robert@fedoraproject.org> 39c-2
- Added default configuration /etc/mkshrc & /etc/skel/.mkshrc
as default skel (like at bash; thanks to Michal Hlavinka)