From:             [EMAIL PROTECTED]
Operating system: N/A
PHP version:      4.0.4pl1
PHP Bug Type:     Unknown/Other Function
Bug description:  (8212) If the result of an exec() command is one character the 
result is empty.

This is the solution to problem 8212
File:  ext/standard/exec.c
Function _Exec:



However, it should contain:

RETVAL_STRINGL(buf,l?l+1:((isspace((int)buf[0]) || !buf[0])?0:1),1);

The problem lies in code previous which reads:
                /* strip trailing spaces */
                l = strlen(buf);
                t = l;
                while (l && isspace((int)buf[--l]));
                if (l < t) buf[l + 1] = '\0';

Obviously if the return value ends with the last line being a single character that 
DOES NOT end with a \n, then strlen(buf) = 1 and the variable l ends up as 0.

The trim code leaves us in an ambiguous position after it is completed.  The problem 
is that it operates under the assumption that we end with a newline character.  This 
is not always the case.  I suppose this is the problem with trying to trim whitespace 
in one line of code!

The suggested codefix simply checks when l==0 if buf[0] was actually trimmable, if 
not, then we know we have to return exactly one character (instead of 0.)  I have 
tested my solution and it seems to work.

An alternate proposal would be to originally compute the trim in a more normal way:
                while (l && isspace((int)buf[l-1])) l--;
But this affects more than one line of code.

Edit Bug report at:

PHP Development Mailing List <>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to