|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-02-22 05:21 UTC] stas@php.net
[2001-04-28 09:20 UTC] elixer@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 13:00:01 2025 UTC |
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.