php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13813 Character '+' used as argv separator in sapi version
Submitted: 2001-10-24 09:45 UTC Modified: 2002-03-21 12:25 UTC
Votes:3
Avg. Score:4.3 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: rxdev at serianet dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.6 OS: Linux 2.2.19
Private report: No CVE-ID: None
 [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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-21 12:19 UTC] php at Cipri dot com
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.
 [2002-03-21 12:25 UTC] mfischer@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 18:01:30 2024 UTC