|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-21 10:25 UTC] andre dot huebner at gmx dot de
Description:
------------
seems that htscanner is adding a linebreak to path-values when php is compiled for fastcgi (--enable-fastcgi)
mod_php, php_cli works fine, just php-cgi is the exception...
.htaccess:
php_value session.save_path /path/to/path/to/path
Reproduce code:
---------------
<?
echo ini_get("session.save_path")."<==";
?>
Expected result:
----------------
/path/to/path/to/path<===
Actual result:
--------------
/path/to/path/to/path
<===
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 03:00:01 2025 UTC |
I have a server with php running as Fast-cgi (so it's compilled with enable-fastcgi option), and I had the same issue, but I reproduced it when I tried to set memory_limit with 'M/G/K' modificator, and my .htaccess was in Unix format. However it seems, the issue is not related to the option, but it should be in place whether the option exists or not. Please note, I did not try to use it w/o enable-fastcgi option, as the server I use the module on is running FastCGI PHP and it requires the option to be used. I dug the code and found that the issue was in value_hnd_strip function, here: /* strip any leading whitespaces or tabs from the value */ value_len = strlen(value); if (value_len > 2 && value[value_len - 2] == '\r') { value[value_len - 2] = 0; } else { value[value_len] = 0; } Short background: strlen returns length of the string in chars, for example for 'asd' it returns 3. However, 1st char ('a') in the char array (string) has index 0 and the last 'd' in our case has index 2. Index value_len will always point to end of the string mark '\0'. So, what do we have here? 1st we check, if a string is longer than 2 chars and prelast char of it is '\r' (that's for DOS strings, we're looking for DOS newline '\r\n'), if the expression is true, we replace '\r' (which is start of new line in DOS format) with '\0', i.e truncate DOS new line mark. That works ok. Otherwise, we just try to truncate Unix format new line mark '\n' which is at value_len-1 position in reality, however, instead of replaicing it, we do replace the end of the string mark '\0'. I solved the problem on my server by applying the patch: --- htscanner-0.9.0/htscanner.c 2009-03-03 18:00:07.000000000 -0600 +++ htscanner.c.correct 2010-01-13 06:47:14.000000000 -0600 @@ -189,7 +189,7 @@ if (value_len > 2 && value[value_len - 2] == '\r') { value[value_len - 2] = 0; } else { - value[value_len] = 0; + value[value_len - 1] = 0; } /* strip quoting characters */ But as I told I did not test it without enable-fastcgi option set. I admit, that in some cases, behaviour of file read functions in php can be different (in some cases it returns strings with \r\n, but in some w/o). To avoid the issue in the future I would replace this code block with completely new one: /* strip any trailing whitespaces or tabs from the value */ value_len = 0; while (((value_len = strlen(value)) > 0) && ((value[value_len - 1] == '\r')||(value[value_len - 1] == '\n'))) value[value_len - 1] = 0;A little addon: Server I had the problem is running Centos 5.4, PHP 5.2.12. Also, if you decide to use code I gave, it's easy to add there tabs, spaces, quotes and d-quotes (which is supposed to be there according to the comment): /* strip any trailing whitespaces or tabs from the value */ value_len = 0; while (((value_len = strlen(value)) > 0) && ( \ (value[value_len - 1] == '\r')|| \ (value[value_len - 1] == '\n')|| \ (value[value_len - 1] == '\t')|| \ (value[value_len - 1] == '"') || \ (value[value_len - 1] == '\'')|| \ )) value[value_len - 1] = 0;