php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8962 (8212) If the result of an exec() command is one character the result is empty.
Submitted: 2001-01-28 00:15 UTC Modified: 2001-04-28 09:20 UTC
From: bram at xspace dot com Assigned:
Status: Closed Package: Program Execution
PHP Version: 4.0.4pl1 OS: N/A
Private report: No CVE-ID: None
 [2001-01-28 00:15 UTC] bram at xspace dot com
This is the solution to problem 8212
File:  ext/standard/exec.c
Function _Exec:

Contains:

RETVAL_STRINGL(buf,l?l+1:0,1);

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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-22 05:21 UTC] stas@php.net
reclassify
 [2001-04-28 09:20 UTC] elixer@php.net
Fixed in CVS.  Wait for 4.0.6.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 20:01:25 2019 UTC