Re: /bin/sh dumps core with here-document of 8bit text

[ Available lists | Index of freebsd-current | Month of Jul 2000 | Week of 28 Jul 2000 | Raw email | View thread | Wrap long lines | Reply | Tag ]
From
Martin Cracauer <cracauer@cons.org>
Date
28 Jul 2000 00:47:16
Subject
Re: /bin/sh dumps core with here-document of 8bit text
Message-ID
20000728094707.A10655@cons.org


[ Hide this part ]
In <20000728.150627.74708840.ume@mahoroba.org>, Hajimu UMEMOTO wrote:
> >>>>> On Fri, 28 Jul 2000 12:09:51 +0900
> >>>>> Jun Kuriyama <kuriyama@FreeBSD.org> said:
>
> kuriyama> Shell script which contains here-document of 8bit text sometimes dumps
> kuriyama> core. For example, please test this script in 4.1 or -current.
>
> I'm using this for workaround on IMASY's main server. 3.5-RELEASE or
> later have this problem.
>
> --- bin/sh/parser.c.orig Mon Mar 20 19:51:04 2000
> +++ bin/sh/parser.c Fri Jun 30 17:15:38 2000
> @@ -909,9 +909,11 @@
> for (;;) { /* until end of line or end of word */
> CHECKSTRSPACE(3, out); /* permit 3 calls to USTPUTC */
>
> +#if 0
> if (c < 0 && c != PEOF)
> synentry = CWORD;
> else
> +#endif
> synentry = syntax[c];
>
> switch(synentry) {

Hm, looks like I broke that in my 8-bit fixes. This code is native in
that it passed control chars further down in the hope noone will
execute them anymore, just taking them for real chars. Nice try.

The problem is also not limited to here-documents:
echo \202 # A real \202
will also dump core.

Since literal strings cannot be made 8-bit clean without further
cleanup, I think we should make this official, although in the
following form, otherwise wrong characters are echoed.

Anyone for whom this fix doesn't work?

Martin
--
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer/
BSD User Group Hamburg, Germany http://www.bsdhh.org/


[ Hide this part ]
? test2
? test1
? l
? Makefile.cra
? builtins.c
? builtins.h
? mknodes
? nodes.h
? nodes.c
? mksyntax
? syntax.c
? syntax.h
? token.h
? y.tab.h
? y.tab.c
? arith.c
? arith_lex.c
? sh
? l4
? mkinit
? init.c
? sh.1.gz
? .depend
? l3
? l2
? foo
? l5
Index: parser.c
===================================================================
RCS file: /home/CVS-FreeBSD/src/bin/sh/parser.c,v
retrieving revision 1.31
diff -c -r1.31 parser.c
*** parser.c 2000/05/15 13:02:07 1.31
--- parser.c 2000/07/28 07:46:22
***************
*** 909,918 ****
for (;;) { /* until end of line or end of word */
CHECKSTRSPACE(3, out); /* permit 3 calls to USTPUTC */

! if (c < 0 && c != PEOF)
synentry = CWORD;
! else
! synentry = syntax[c];

switch(synentry) {
case CNL: /* '\n' */
--- 909,923 ----
for (;;) { /* until end of line or end of word */
CHECKSTRSPACE(3, out); /* permit 3 calls to USTPUTC */

! if (c >= CTLESC && c <= CTLQUOTEMARK) {
synentry = CWORD;
! fprintf(stderr,
! "Warning: internal control character in "
! "literal text, using '?' instead\n");
! c = '?';
! }
!
! synentry = syntax[c];

switch(synentry) {
case CNL: /* '\n' */



Elapsed time: 0.176 seconds