ports/160263: SHELL/BASH bug: testing condition for [ -x file ] is wrong

Alexander Verbod AN47HDTEMVQLKX3.NJKM2YX7YWVLP2 at gmail.com
Sun Aug 28 20:10:11 UTC 2011


>Number:         160263
>Category:       ports
>Synopsis:       SHELL/BASH bug: testing condition for [ -x file ] is wrong
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 28 20:10:10 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Alexander Verbod
>Release:        8.2 release
>Organization:
>Environment:
FreeBSD dev.local 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Fri Feb 18 02:24:46 UTC 2011     root at almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

Also tested under:

FreeBSD devel.loc 7.4-RELEASE FreeBSD 7.4-RELEASE #0: Thu Feb 17 03:51:56 UTC 2011     root at walker.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
Conditional expression like:

if [[ -x '/path/file' ]]; then 
or 
if [ -x '/path/file' ]; then

does not work as expected and report on file with permission set to 444 as executable.

The same conditions test under Linux(Ubuntu)works as expected.

>How-To-Repeat:
Run following script:



#! /usr/local/bin/bash
echo '======================= <BASH_bug_test> ================================';

Test_DIR=".";
Test_file="${Test_DIR}/TestFile";

/bin/echo 'Test File' >"${Test_file}";

# Set READ ONLY permissions on test file
/bin/chmod 444 "${Test_file}";


if [[ -x "${Test_file}" ]]; then        #---- bash's bug on FreeBSD

    /bin/echo "After: /bin/chmod 444 '${Test_file}' operation";
    /bin/echo "BASH think that file '${Test_file}' is EXECUTABLE,";
    /bin/echo 'on statement like: "if [[ -x "${Test_file}" ]]; then ...", but...';
    /bin/echo "/bin/ls think differently:"; /bin/echo;
    /bin/ls -laoF "${Test_file}"; /bin/echo;

    if /bin/test ! -x "${Test_file}"; then
        /bin/echo '/bin/test agree with /bin/ls too that';
        /bin/echo "'${Test_file}' is not executable"; /bin/echo;
    fi

    if [ -x "${Test_file}" ]; then        # [ aka test is not smarter eather
        /bin/echo;
        /bin/echo "BTW, BASH's"' internal "[" aka "test"';
        /bin/echo '    if [ -x "${Test_file}" ]; then ...';
        /bin/echo 'is not smarter eather :(';
    else
        /bin/echo 'Construction like: "if [ -x "${Test_file}" ]; then ..." is work.';
    fi
else
    /bin/echo "File '${Test_file}' is NOT executable";
fi

/bin/rm -f "${Test_file}"       # Be nice, clean up own poop

echo '======================= </BASH_bug_test> ===============================';
exit 0

>Fix:


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



More information about the freebsd-ports-bugs mailing list