|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-10-24 09:45 UTC] rxdev at serianet dot com
The '+' character is used as argv separator in the sapi version of PHP4. Therefore, executing this script:
<?php
// myscript.php
echo "first=".$argv[1]."\n";
echo "second=".$argv[2]."\n";
?>
Will produce incoherent results if you put a + in one of the argmuments:
# php -q myscript.php "tomatoes and garlic"
first=tomatoes and garlic
second=
# php -q myscript.php "tomatoes+garlic"
first=tomatoes
second=garlic
The bug is located in PHP source file 'sapi/cgi/cgi_main.c',
line 643 and above,
in function 'int main(int argc, char *argv[])'
...
if (script_file) {
strcpy(s, script_file);
strcat(s, "+");
// ^^^^^^^^ '+' AS SEPARATOR
}
for (i = ap_php_optind, len = 0; i < argc; i++) {
strcat(s, argv[i]);
if (i < (argc - 1)) {
strcat(s, "+");
// ^^^^^^^^ '+' AS SEPARATOR
}
}
...
A quick-and-easy fix might be to use '\n' as separator, or any other non standard (ascii<32) character.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 14:00:01 2025 UTC |
4.0.6-7 on Linux 2.4.9-31 I had a similar issue, whlie running the following script: /etc/mgetty+sendfax/fax-fail /var/spool/fax/outgoing/F000052/JOB after some odd behaviour and debugging, I did a print_r($argv) which showed this: Array ( [0] => /etc/mgetty [1] => sendfax/fax-fail [2] => /var/spool/fax/outgoing/F000052/JOB ) apparantly, it also chops out the + signs from the script name itself.That's fixed in CVS (and I think upcomming php4.2 also has it): mfischer@devel01:~/tmp$ php -r 'var_dump($argv);' -- /etc/mgetty+sendfax/fax-fail array(2) { [0]=> string(1) "-" [1]=> string(28) "/etc/mgetty+sendfax/fax-fail" } mfischer@devel01:~/tmp$ php -v 4.2.1-dev