NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/45430: ash uses argv[0] as $0 for scripts without #!



The following reply was made to PR bin/45430; it has been noted by GNATS.

From: Nikolai Kondrashov <spbnick%gmail.com@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
Subject: Re: bin/45430: ash uses argv[0] as $0 for scripts without #!
Date: Thu, 6 Oct 2011 13:08:54 +0300

 On Wed, Oct 5, 2011 at 9:55 PM, David Laight <david%l8s.co.uk@localhost> wrote:
 > =A0This isn't a bug!
 > =A0For a normal program binary argv[0] is whatever the user typed, this
 > =A0also applies to non #! scripts executed by the shell.
 >
 > =A0The execution of #! scripts is done by the kernel which has to
 > =A0pass the interpreter the full pathname of the script file.
 
 Sorry, I forgot #! scripts are executed by the kernel for a moment,
 while looking for a reason to change this (wishful thinking?).
 
 I agree that this is not strictly a bug from the architecture standpoint.
 However, in the user's view this may seem strange and inconsistent and
 could be confusing.
 Especially considering bash, dash, busybox, zsh, csh, and tcsh (but
 not ksh) do supply full path in $0 in that case.
 It seems a practical thing to do.
 
 I do, of course, pursue my own goals here.
 I need this to work around "peculiar" Android filesystem hierarchy to
 have scripts run both on the device and on host.
 Details, if anyone is curious:
 https://plus.google.com/109969355357893765097/posts/2tmx3gmK3yY
 
 I could change it in our branch, no problem, or try to convince Google
 developers. I just hoped it could be seen by upstream as a useful
 thing to have, so I wouldn't have to maintain it :)
 
 If nothing else, could you please confirm that the patch above doesn't
 break anything?
 
 Thank you very much :)
 
 > =A0For suid #! scripts the kernel will pass the name of an open fd
 > =A0(as /dev/fd/n) as argv[0] to be absolutely sure the correct file
 > =A0is opened (no symlink dances).
 >
 > =A0This has the 'odd' side effect that you normally need 'rx' permissions
 > =A0to run a #! script - unless it is suid and you aren't the owner, in
 > =A0which case 'x' is enough.
 
 Thanks, I didn't know that!
 


Home | Main Index | Thread Index | Old Index