BusyBox Bug and Patch Tracking
BusyBox
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0001380 [BusyBox] Other major always 06-05-07 08:44 06-08-07 00:34
Reporter dmaizer View Status public  
Assigned To BusyBox
Priority normal Resolution fixed  
Status closed   Product Version 1.4.x
Summary 0001380: /usr/bin/[ gives "[: ]: unknown operand" message
Description We are working in an Apache (httpd 2.2.3) suexec CGI scripts environment and our CGI scripts need to provide full paths to all applets/programs used, so we have something like the following in the CGI script:

if /usr/bin/[ $# -lt 1 ]; then
   /bin/echo "sitediag: too few arguments"
   /bin/echo "Try sitediag --help for more information"
   exit 1
fi

However - this gives the error:
[: ]: unknown operand

Meaning that the "]" closing bracket is being recognized as an unknown operand. But of course this bracket is needed to close the test...

If we remove the /usr/bin prefix from [ - then it works and gives the expected echo messages above.

I tried looking at busybox code (being no expert of that code) and found the following in coreutils/test.c:

    if (*t_wp != NULL && *++t_wp != NULL) {
        bb_error_msg("%s: unknown operand", *t_wp);
        return 2;
    }

My guess is that somehow using the pathname causes that condition above to be true, but I haven't been able to find out why yet (I started looking from ash.c and "lower" to see why this happens, but haven't been able to find anything meaningful so far - hopefully someone who knows the code better can provide a clue or a fix.
Additional Information
Attached Files

- Relationships

- Notes
(0002442)
dmaizer
06-05-07 08:45

We use version 1.4.2 of busybox...
 
(0002443)
bernhardf
06-05-07 09:26

confirmed.

As a quick workaround, just use "test" instead of "[" or "[[".

I will also note, that the check for surplus args is borked (as you note) since some closing brackets are a legit character to see -- IFF we were called as "[" one and two otherwise.

For the sake of code-size, there is currently no checking for the correct number of closing brackets, so just omitting any closing bracket bypasses the reported behaviour.
 
(0002464)
vda
06-08-07 00:34

Fixed in rev 18775, thanks
 

- Issue History
Date Modified Username Field Change
06-05-07 08:44 dmaizer New Issue
06-05-07 08:44 dmaizer Status new => assigned
06-05-07 08:44 dmaizer Assigned To  => BusyBox
06-05-07 08:45 dmaizer Note Added: 0002442
06-05-07 09:26 bernhardf Note Added: 0002443
06-08-07 00:34 vda Status assigned => closed
06-08-07 00:34 vda Note Added: 0002464
06-08-07 00:34 vda Resolution open => fixed


Copyright © 2000 - 2006 Mantis Group
Powered by Mantis Bugtracker