From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29773 invoked from network); 16 Jun 1999 09:21:03 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 16 Jun 1999 09:21:03 -0000 Received: (qmail 1347 invoked by alias); 16 Jun 1999 09:20:38 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6658 Received: (qmail 1337 invoked from network); 16 Jun 1999 09:20:19 -0000 Message-Id: <9906160851.AA38825@ibmth.df.unipi.it> To: zsh-workers@sunsite.auc.dk Subject: PATCH: pws-22: Re: execve bug In-Reply-To: ""Bart Schaefer""'s message of "Wed, 16 Jun 1999 06:56:37 DFT." <990616065637.ZM25982@candle.brasslantern.com> Date: Wed, 16 Jun 1999 10:51:36 +0200 From: Peter Stephenson "Bart Schaefer" wrote: > On Jun 14, 1:13pm, David Aspinwall wrote: > } Subject: execve bug > } > } If you have a script called 'dog' whose first line is '#!/bin/sh ' > } (i.e., has at least one space after the interpreter name), and > } the OS doesn't support #!, zsh will wind up calling execve with > } an argv of ("/bin/sh", "", "dog"). > > Thanks for pointing this out. The same problem happens with a trailing > tab, so I think the following patch is better. There was also no reason > for the old code wandereding all the way to t0 == ct clobbering newlines > once the first one was found. This is needed in 3.1.5 as well and applies with a bit of offset. This reminds me... One of my colleagues in Zeuthen complained to me about something similar a couple of years ago (with the usual complaints about how everything was becoming incompatible and it was a crying shame, etc.) and I sent a patch. The problem was this: % cat tst #!/home/user2/pws/bin/zsh -f # ^^^^^^^^spaces here print "hello, world" % ./tst zsh: bad option: - and I've discovered Bart's reply to it in 2797 (why not the original message or my followup? is the archive smart enough to know they appear as links?) and hence my reply to that in 2798. We sort of agreed on Bart's (3): > 2. Stop parsing options at whitespace, and completely ignore it and > all the characters that come after it. I believe BSD 4.2 csh did > this, if I'm remembering correctly my early days of feeling my way > through scripting. > > 3. As (2), but issue an error if there's anything other than whitespace > in the trailing part. I think this is the most reasonable choice, as > it doesn't silently drop stuff from the #! line (which was mystifying > when it happened in csh, which is why I'm pretty sure I remember it). However, the patch got ignored. Here's a new version which won't be --- unless anyone can think of a good reason why it would be safer simply to report a better error. This should presumably fit seamlessly into 3.0.6, apart from massaging the documentation (and in certain quarters it will be regarded as a bug fix). --- Doc/Zsh/options.yo.spc Fri Jun 11 13:36:55 1999 +++ Doc/Zsh/options.yo Wed Jun 16 10:37:25 1999 @@ -34,6 +34,12 @@ in which case the inversion of that name refers to the option being on. For example, `tt(PLUS()n)' is the short name of `tt(exec)', and `tt(-n)' is the short name of its inversion, `tt(noexec)'. + +In strings of single letter options supplied to the shell at startup, +trailing whitespace will be ignored; for example the string `tt(-f )' +will be treated just as `tt(-f)', but the string `tt(-f i)' is an error. +This is because many systems which implement the `tt(#!)' mechanism for +calling scripts do not strip trailing whitespace. texinode(Description of Options)(Option Aliases)(Specifying Options)(Options) sect(Description of Options) cindex(options, description) --- Src/init.c.spc Mon Jun 14 17:39:43 1999 +++ Src/init.c Wed Jun 16 10:33:12 1999 @@ -194,6 +194,7 @@ /* loop through command line options (begins with "-" or "+") */ while (*argv && (**argv == '-' || **argv == '+')) { + char *args = *argv; action = (**argv == '-'); if(!argv[0][1]) *argv = "--"; @@ -228,6 +229,14 @@ restricted = action; else dosetopt(optno, action, 1); + break; + } else if (isspace(**argv)) { + /* zsh's typtab not yet set, have to use ctype */ + while (*++*argv) + if (!isspace(**argv)) { + zerr("bad option string: `%s'", args, 0); + exit(1); + } break; } else { if (!(optno = optlookupc(**argv))) { -- Peter Stephenson Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy