execvp

Guy Harris guy%gorodish at Sun.COM
Fri Jan 23 13:42:33 AEST 1987


> According to the ("exec") "man" page,
> 
> 	If execvp is called to execute a file that turns out to be a 
> 	shell command file, and if it is impossible to execute the
> 	shell, the values of argv[0] and argv[-1] will be modified
> 	before return.
> 
> This seemed very strange to me.  Which "argv"?  Why does it mess with
> argv[-1]??
> ...
> In short I can't cause this "bug" to manifest itself; does it really
> exist?

Nope.  This same claim is in the V7 manual page.  It may have been
true back then; I don't have V7 source handy to check.

The 4.2BSD and S5 code do the same thing if the file is a shell
script.  They build a new argument list, whose first entry is "sh",
whose second entry is the name of the file that it found, and whose
subsequent entries are the 1st through Nth arguments (i.e., argv[1]
through argv[argc-1]).  My pure guess is that if this bug ever
existed, it was because some version of "execvp" *didn't* make a copy
of the argument list, but just smashed argv[0] with the name of the
file and argv[-1] with "sh" and fed this somewhat spurious argument
list to "execv".  Needless to say, smashing argv[-1] is violently
anti-social, since it's probably some random piece of user data.

Given that the 4.2BSD and S5 code are basically the same, I suspect
that the fix was in some version of UNIX from Research that predates
both of them.  A likely candidate for this version would be V7; it
may be that the documentation, as usual, trailed the code.



More information about the Comp.unix.wizards mailing list