|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: bram at xspace dot com
New email:
PHP Version: OS:


 [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:



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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-02-22 05:21 UTC]
 [2001-04-28 09:20 UTC]
Fixed in CVS.  Wait for 4.0.6.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 06:01:35 2024 UTC