From 68cc2f890e531f8fbab96af900fa7fde9cd5ca07 Mon Sep 17 00:00:00 2001 From: yar Date: Mon, 4 Jun 2007 11:39:35 +0000 Subject: Be robust to a bogus script specification or contents when figuring out what the real interpreter is for an interpreted command. That is, check whether we can read the script file in the first place and, if so, make sure we got a valid shebang line from it. --- etc/rc.subr | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/etc/rc.subr b/etc/rc.subr index 061f0b9..f0a2c9d 100644 --- a/etc/rc.subr +++ b/etc/rc.subr @@ -283,17 +283,30 @@ _find_processes() _pref= if [ $_interpreter != "." ]; then # an interpreted script - # read interpreter name - read _interp < ${_chroot}${_chroot:+"/"}$_procname - _interp=${_interp#\#!} # strip #! - set -- $_interp - case $1 in - */bin/env) - shift # drop env to get real name - ;; - esac - if [ $_interpreter != $1 ]; then - warn "\$command_interpreter $_interpreter != $1" + _script=${_chroot}${_chroot:+"/"}$_procname + if [ -r $_script ]; then + read _interp < $_script # read interpreter name + case "$_interp" in + \#!*) + _interp=${_interp#\#!} # strip #! + set -- $_interp + case $1 in + */bin/env) + shift # drop env to get real name + ;; + esac + if [ $_interpreter != $1 ]; then + warn "\$command_interpreter $_interpreter != $1" + fi + ;; + *) + warn "no shebang line in $_script" + set -- $_interpreter + ;; + esac + else + warn "cannot read shebang line from $_script" + set -- $_interpreter fi _interp="$* $_procname" # cleanup spaces, add _procname _interpbn=${1##*/} -- cgit v1.1