From 4de76ca84294835ec63caefd139bd4b16eb99d23 Mon Sep 17 00:00:00 2001 From: Michal Hlavinka Date: Jul 21 2010 14:24:25 +0000 Subject: - fix crash when alias contains alias - fix crash when xtrace is enabled --- diff --git a/mksh-39c-dblalias.patch b/mksh-39c-dblalias.patch new file mode 100644 index 0000000..fd04f5f --- /dev/null +++ b/mksh-39c-dblalias.patch @@ -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 diff --git a/mksh-39c-fixsetx.patch b/mksh-39c-fixsetx.patch new file mode 100644 index 0000000..d2917fe --- /dev/null +++ b/mksh-39c-fixsetx.patch @@ -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; diff --git a/mksh.spec b/mksh.spec index 602870d..6112717 100644 --- a/mksh.spec +++ b/mksh.spec @@ -3,12 +3,14 @@ Summary: MirBSD enhanced version of the Korn Shell Name: mksh Version: 39c -Release: 1%{?dist} +Release: 2%{?dist} License: MirOS Group: System Environment/Shells URL: http://www.mirbsd.de/%{name}/ Source0: http://www.mirbsd.org/MirOS/dist/mir/%{name}/%{name}-R%{version}.cpio.gz Source1: http://www.mirbsd.org/MirOS/dist/hosted/other/arc4random.c +Patch1: mksh-39c-fixsetx.patch +Patch2: mksh-39c-dblalias.patch Requires(post): grep Requires(postun): coreutils, grep BuildRequires: util-linux, ed @@ -29,6 +31,12 @@ gzip -dc %{SOURCE0} | cpio -imd mv %{name}/* . && rm -rf %{name} cp -f %{SOURCE1} . +# 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 @@ -71,6 +79,10 @@ rm -rf $RPM_BUILD_ROOT %{_mandir}/man1/%{name}.1* %changelog +* Wed Jul 21 2010 Michal Hlavinka 39c-2 +- fix crash when alias contains alias +- fix crash when xtrace is enabled + * Sat Feb 27 2010 Robert Scheck 39c-1 - Upgrade to 39c and updated arc4random.c file