zsh-users
 help / color / mirror / code / Atom feed
* Using 'command -v' in a shellscript results in a coredump
@ 2004-08-18 23:29 Michael Prokop
  2004-08-19  7:11 ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Prokop @ 2004-08-18 23:29 UTC (permalink / raw)
  To: zsh-users

Hello,

on my system /bin/sh is a symlink to /bin/zsh4 (version 4.2.1).

I noticed a strange behaviour with the following shellscript:

#!/bin/sh
set -e
command -v blub > /dev/null 2>&1

Running it results in 'zsh: segmentation fault (core dumped)'.
Running the script with /bin/sh pointing to /bin/bash does not
produce a core dump.

Regarding to the zsh-manual 'command' is defined as:

 ,---- [ man zsh ]
 | command [ -pvV ] simple command
 |
 |  The  simple  command argument is taken as an external command
 |  instead of a function or builtin and is executed. If the
 |  POSIX_BUILTINS option is set, builtins will also be executed but
 |  cer- tain  special  properties  of  them are  suppressed.  The -p
 |  flag causes a default path to be searched instead of that in
 |  $path. With the -v flag, command is similar to whence and with -V,
 |  it is equivalent to whence -v.
 `----

Regarding to "IEEE Std 1003.1-2001, Section 12.2, Utility Syntax
Guidelines" 'command -v' is defined as:

 ,---- [ command -v ]
 | -v
 | (On systems supporting the User Portability Utilities option.) Write
 | a string to standard output that indicates the pathname or command
 | that will be used by the shell, in the current shell execution
 | environment (see Shell Execution Environment ), to invoke
 | command_name, but do not invoke command_name.
 `----

I'm not sure whether it's a bug in the shellscript (use of
non-sh-code) or the behaviour of zsh in sh-mode isn't correct.
Could anyone please explain me what's going on?

Thanks && regards,
(-: Michael
-- 
www.michael-prokop.at
~
~
".signature" [New] 1L, 22C [w]


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using 'command -v' in a shellscript results in a coredump
  2004-08-18 23:29 Using 'command -v' in a shellscript results in a coredump Michael Prokop
@ 2004-08-19  7:11 ` Bart Schaefer
  2004-10-07 17:55   ` Michael Prokop
  0 siblings, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2004-08-19  7:11 UTC (permalink / raw)
  To: zsh-users

On Thu, 19 Aug 2004, Michael Prokop wrote:

> #!/bin/sh
> command -v blub > /dev/null 2>&1
> 
> Running it results in 'zsh: segmentation fault (core dumped)'.

The following prevents the core dump without producing any errors from
"make test", but I suspect there's something deeper that should be fixed
instead.

The crash happens whenever 'command -v' or 'command -V' is used with the 
POSIXBUILTINS option set.

The problem is that the code in execcmd() near line 1848 assigns 'hn' to
point at the special 'commandbn' struct, but then 1952 is reached and
tries (again) to find the builtin named "command" which fails.  Nothing
picks up the error after that and a null 'hn' is eventually dereferenced
by execbuiltin().

Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.69
diff -u -r1.69 exec.c
--- Src/exec.c	29 Jul 2004 15:09:51 -0000	1.69
+++ Src/exec.c	19 Aug 2004 07:03:43 -0000
@@ -1949,7 +1949,7 @@
 		is_shfunc = 1;
 		break;
 	    }
-	    if (!(hn = builtintab->getnode(builtintab, cmdarg))) {
+	    if (!hn && !(hn = builtintab->getnode(builtintab, cmdarg))) {
 		if (cflags & BINF_BUILTIN) {
 		    zwarn("no such builtin: %s", cmdarg, 0);
 		    lastval = 1;


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using 'command -v' in a shellscript results in a coredump
  2004-08-19  7:11 ` Bart Schaefer
@ 2004-10-07 17:55   ` Michael Prokop
  2004-10-08 13:53     ` Clint Adams
  2004-10-11 22:29     ` Using 'command -v' in a shellscript results in a coredump Bart Schaefer
  0 siblings, 2 replies; 8+ messages in thread
From: Michael Prokop @ 2004-10-07 17:55 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer <schaefer@brasslantern.com> [20040819 09:15]:
> On Thu, 19 Aug 2004, Michael Prokop wrote:

> > #!/bin/sh
> > command -v blub > /dev/null 2>&1

> > Running it results in 'zsh: segmentation fault (core dumped)'.

> The following prevents the core dump without producing any errors from
> "make test", but I suspect there's something deeper that should be fixed
> instead.

> The crash happens whenever 'command -v' or 'command -V' is used with the 
> POSIXBUILTINS option set.

> The problem is that the code in execcmd() near line 1848 assigns 'hn' to
> point at the special 'commandbn' struct, but then 1952 is reached and
> tries (again) to find the builtin named "command" which fails.  Nothing
> picks up the error after that and a null 'hn' is eventually dereferenced
> by execbuiltin().

> Index: Src/exec.c
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
> retrieving revision 1.69
> diff -u -r1.69 exec.c
> --- Src/exec.c	29 Jul 2004 15:09:51 -0000	1.69
> +++ Src/exec.c	19 Aug 2004 07:03:43 -0000
> @@ -1949,7 +1949,7 @@
>  		is_shfunc = 1;
>  		break;
>  	    }
> -	    if (!(hn = builtintab->getnode(builtintab, cmdarg))) {
> +	    if (!hn && !(hn = builtintab->getnode(builtintab, cmdarg))) {
>  		if (cflags & BINF_BUILTIN) {
>  		    zwarn("no such builtin: %s", cmdarg, 0);
>  		    lastval = 1;

Thanks, Bart. (I'm replying with latency because I wanted to wait
for any updates on this topic.)

In the current CVS sources from zsh (2004-10-07) this bug isn't
fixed AFAICS (refering to line 1978 of Src/exec.c).

Some post-install scripts on Debian systems use 'command -v'.
I'm using zsh as the '/bin/sh'-shell on my systems. When I'm
upgrading the systems I often have to do a 'rm /bin/sh; ln -s
/bin/bash /bin/sh' and point it back after process of upgrading to
avoid the mentioned core dumps.

Any chance to see this bug fixed in upcoming versions of zsh (with
above code)?

thx && regards,
(-: Michael


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using 'command -v' in a shellscript results in a coredump
  2004-10-07 17:55   ` Michael Prokop
@ 2004-10-08 13:53     ` Clint Adams
  2004-10-09 20:50       ` simple question about completion and case William Scott
  2004-10-11 22:29     ` Using 'command -v' in a shellscript results in a coredump Bart Schaefer
  1 sibling, 1 reply; 8+ messages in thread
From: Clint Adams @ 2004-10-08 13:53 UTC (permalink / raw)
  To: zsh-users

> Some post-install scripts on Debian systems use 'command -v'.

File bugs against them; they're violating policy.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* simple question about completion and case
  2004-10-08 13:53     ` Clint Adams
@ 2004-10-09 20:50       ` William Scott
  2004-10-11 22:31         ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: William Scott @ 2004-10-09 20:50 UTC (permalink / raw)
  To: zsh-users


Dear zsh folks:

Since I use Mac OS X, I wrote a very simple-minded completion
for the "open -a" command.

The command "open -a Foo" is the functional equivalent of clicking
on the application named Foo.  The -a specifies it is an application.


compctl -f -x 'p[2]' -s "(list of the applications available)" -- open


where list of the applications available contains elements like  Preview
and Mail and so on that are in title case.  It works ok.

I would like to be able to type

open -a preview

and have it corrected to

open -a Preview

Is there a way to do so for the open  command and not globally?  Sorry if
this
is obvious to everyone but me but I spent a fair amount of time with the
manual and experimenting to no avail.

Many thanks in advance.

Bill Scott



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using 'command -v' in a shellscript results in a coredump
  2004-10-07 17:55   ` Michael Prokop
  2004-10-08 13:53     ` Clint Adams
@ 2004-10-11 22:29     ` Bart Schaefer
  2004-10-13 22:09       ` Michael Prokop
  1 sibling, 1 reply; 8+ messages in thread
From: Bart Schaefer @ 2004-10-11 22:29 UTC (permalink / raw)
  To: zsh-users; +Cc: Michael Prokop

On Thu, 7 Oct 2004, Michael Prokop wrote:

> In the current CVS sources from zsh (2004-10-07) this bug isn't
> fixed AFAICS (refering to line 1978 of Src/exec.c).

The bug was fixed a different way, so you're looking at the wrong part of 
the code.

2004-09-08  Bart Schaefer  <schaefer@zsh.org>

	* 20325: Src/exec.c, Test/E01options.ztst: fix crash when using
	the "command" builtin (as opposed to the "command" precommand
	modifier) when POSIX_BUILTINS is set; (unposted) add test for that
	and also for EVAL_LINENO.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: simple question about completion and case
  2004-10-09 20:50       ` simple question about completion and case William Scott
@ 2004-10-11 22:31         ` Bart Schaefer
  0 siblings, 0 replies; 8+ messages in thread
From: Bart Schaefer @ 2004-10-11 22:31 UTC (permalink / raw)
  To: zsh-users; +Cc: William Scott

On Sat, 9 Oct 2004, William Scott wrote:

> I would like to be able to type
> 
> open -a preview
> 
> and have it corrected to
> 
> open -a Preview
> 
> Is there a way to do so for the open  command and not globally?

Not without using the function-based completion system, and not easily 
without typing something (e.g. a TAB) to invoke the correction before you
press the return key to accept the command.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Using 'command -v' in a shellscript results in a coredump
  2004-10-11 22:29     ` Using 'command -v' in a shellscript results in a coredump Bart Schaefer
@ 2004-10-13 22:09       ` Michael Prokop
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Prokop @ 2004-10-13 22:09 UTC (permalink / raw)
  To: zsh-users

* Bart Schaefer <schaefer@brasslantern.com> [20041012 01:15]:
> On Thu, 7 Oct 2004, Michael Prokop wrote:

> > In the current CVS sources from zsh (2004-10-07) this bug isn't
> > fixed AFAICS (refering to line 1978 of Src/exec.c).

> The bug was fixed a different way, so you're looking at the wrong part of 
> the code.

> 2004-09-08  Bart Schaefer  <schaefer@zsh.org>

> 	* 20325: Src/exec.c, Test/E01options.ztst: fix crash when using
> 	the "command" builtin (as opposed to the "command" precommand
> 	modifier) when POSIX_BUILTINS is set; (unposted) add test for that
> 	and also for EVAL_LINENO.

Thanks a lot, Bart.

The bug wasn't fixed in the debian package and I couldn't find the
bugfix in zsh cvs source (I missed the Changelog, sorry) - that's
why I wasn't sure.

Thanks && regards,
(-: Michael


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-10-13 22:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-18 23:29 Using 'command -v' in a shellscript results in a coredump Michael Prokop
2004-08-19  7:11 ` Bart Schaefer
2004-10-07 17:55   ` Michael Prokop
2004-10-08 13:53     ` Clint Adams
2004-10-09 20:50       ` simple question about completion and case William Scott
2004-10-11 22:31         ` Bart Schaefer
2004-10-11 22:29     ` Using 'command -v' in a shellscript results in a coredump Bart Schaefer
2004-10-13 22:09       ` Michael Prokop

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).