Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Sep 2000 14:50:11 -0400 (EDT)
From:      rwatson@freebsd.org
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/21315: Bizarre shell interpreter failure mode
Message-ID:  <200009161850.OAA03050@fledge.watson.org>

next in thread | raw e-mail | index | archive | help


>Number:         21315
>Category:       bin
>Synopsis:       Shells often behave oddly when executing shell scripts
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 16 12:00:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Robert Watson
>Release:        FreeBSD 4.1-STABLE i386
>Organization:
>Environment:

FreeBSD mocking.southhadley.watson.org 4.1-STABLE FreeBSD 4.1-STABLE #1: Mon Aug  7 14:13:19 EDT 2000     root@numocking.gw.tislabs.com:/usr/src/sys/compile/MOCKING  i386

>Description:

Shells appear to behave oddly when executing shell scripts in a number of
situations.

(1) When the kernel discovers that the interpreter used is another
    interpreter, it generally returns ``Exec format error'' (ENOEXEC).
    However, when csh and sh find themselves in the same situation, they
    don't return that error, they execute the script using their own
    interpreter.

(2) When in single-user mode, the sh shell appears to assume that any
    script it runs should be executed using its own interpreter, not
    the interpreter at the top of the file.  In multi-user mode, this
    appears to work fine.

>How-To-Repeat:

(1)

    $ cat /tmp/test1
    #!/tmp/test2
    echo This is test1, meant to execute using test2
    $ cat /tmp/test2
    #!/tmp/test1
    echo This is test2, meant to execute with test1
    $ /tmp/test1
    This is test1, meant to execute using test2
    $ /tmp/test2
    This is test2, meant to execute with test1
    $

I.e., executing test1 resulted in sh executing it, instead of ENOEXEC.
Similarly with test2.  Neither resulted in a recursive call, which is
good.  This seems like a poor failure-mode -- it's inconsistent with
the kernel execve() implementation's failure mode, and it runs things
when you would hope that it wouldn't (always bad).

(2)

Boot to single user mode, select /bin/sh as the shell, and attempt to
execute a shell script relying on csh features.

>Fix:

Not attached.


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200009161850.OAA03050>