summaryrefslogtreecommitdiff
path: root/sapi
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2013-04-11 17:20:31 +0200
committerOndřej Surý <ondrej@sury.org>2013-04-11 17:20:31 +0200
commit5a7c0b1f326279a6d7dba8285e81860e1f0ff8ce (patch)
tree81f2fb75f657f6a90ad1ef8901b9408ce17b20ae /sapi
parentcf099ba2ee4e438bae16c3670a14ce0c4390529a (diff)
downloadphp-5a7c0b1f326279a6d7dba8285e81860e1f0ff8ce.tar.gz
Imported Upstream version 5.5.0~beta3upstream/5.5.0_beta3
Diffstat (limited to 'sapi')
-rw-r--r--sapi/cli/php_cli.c2
-rw-r--r--sapi/cli/ps_title.c21
-rw-r--r--sapi/cli/tests/bug64529.phpt67
-rw-r--r--sapi/cli/tests/bug64544.phpt20
4 files changed, 104 insertions, 6 deletions
diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c
index 4b8bae7f7..729052334 100644
--- a/sapi/cli/php_cli.c
+++ b/sapi/cli/php_cli.c
@@ -1402,7 +1402,7 @@ out:
* Do not move this de-initialization. It needs to happen right before
* exiting.
*/
- cleanup_ps_args(argv);
+ cleanup_ps_args(argv);
exit(exit_status);
}
/* }}} */
diff --git a/sapi/cli/ps_title.c b/sapi/cli/ps_title.c
index a2e47f031..6f3bdb862 100644
--- a/sapi/cli/ps_title.c
+++ b/sapi/cli/ps_title.c
@@ -112,6 +112,7 @@ static const size_t ps_buffer_size = MAX_PATH;
#elif defined(PS_USE_CLOBBER_ARGV)
static char *ps_buffer; /* will point to argv area */
static size_t ps_buffer_size; /* space determined at run time */
+static char *empty_environ[] = {0}; /* empty environment */
#else
#define PS_BUFFER_SIZE 256
static char ps_buffer[PS_BUFFER_SIZE];
@@ -124,6 +125,11 @@ static size_t ps_buffer_cur_len; /* actual string length in ps_buffer */
static int save_argc;
static char** save_argv;
+/*
+ * This holds the 'locally' allocated environ from the save_ps_args method.
+ * This is subsequently free'd at exit.
+ */
+static char** frozen_environ, **new_environ;
/*
* Call this method early, before any code has used the original argv passed in
@@ -145,7 +151,6 @@ char** save_ps_args(int argc, char** argv)
{
char* end_of_area = NULL;
int non_contiguous_area = 0;
- char** new_environ;
int i;
/*
@@ -178,7 +183,8 @@ char** save_ps_args(int argc, char** argv)
* move the environment out of the way
*/
new_environ = (char **) malloc((i + 1) * sizeof(char *));
- if (!new_environ)
+ frozen_environ = (char **) malloc((i + 1) * sizeof(char *));
+ if (!new_environ || !frozen_environ)
goto clobber_error;
for (i = 0; environ[i] != NULL; i++)
{
@@ -188,6 +194,7 @@ char** save_ps_args(int argc, char** argv)
}
new_environ[i] = NULL;
environ = new_environ;
+ memcpy((char *)frozen_environ, (char *)new_environ, sizeof(char *) * (i + 1));
}
#endif /* PS_USE_CLOBBER_ARGV */
@@ -405,9 +412,13 @@ void cleanup_ps_args(char **argv)
#ifdef PS_USE_CLOBBER_ARGV
{
int i;
- for (i = 0; environ[i] != NULL; i++)
- free(environ[i]);
- free(environ);
+ for (i = 0; frozen_environ[i] != NULL; i++)
+ free(frozen_environ[i]);
+ free(frozen_environ);
+ free(new_environ);
+ /* leave a sane environment behind since some atexit() handlers
+ call getenv(). */
+ environ = empty_environ;
}
#endif /* PS_USE_CLOBBER_ARGV */
diff --git a/sapi/cli/tests/bug64529.phpt b/sapi/cli/tests/bug64529.phpt
new file mode 100644
index 000000000..d3755724e
--- /dev/null
+++ b/sapi/cli/tests/bug64529.phpt
@@ -0,0 +1,67 @@
+--TEST--
+Bug #64529 (Ran out of opcode space)
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == "WIN") {
+ die("skip non windows test");
+}
+exec('which expect', $output, $ret);
+if ($ret) {
+ die("skip no expect installed");
+}
+?>
+--FILE--
+<?php
+$expect_executable = trim(`which expect`);
+$php_executable = getenv('TEST_PHP_EXECUTABLE');
+$script = __DIR__ . "/expect.sh";
+
+if (extension_loaded("readline")) {
+ $expect_script = <<<SCRIPT
+
+set php_executable [lindex \$argv 0]
+
+spawn \$php_executable -n -a
+
+expect "php >"
+
+send "echo 'hello world';\n"
+send "\04"
+
+expect eof
+
+exit
+
+SCRIPT;
+
+} else {
+ $expect_script = <<<SCRIPT
+
+set php_executable [lindex \$argv 0]
+
+spawn \$php_executable -n -a
+
+expect "Interactive mode enabled"
+
+send "<?php echo 'hello world';\n"
+send "\04"
+
+expect eof
+
+exit
+
+SCRIPT;
+}
+
+file_put_contents($script, $expect_script);
+
+system($expect_executable . " " . $script . " " . $php_executable);
+
+@unlink($script);
+?>
+--EXPECTF--
+spawn %sphp -n -a
+Interactive %s
+
+%secho 'hello world';
+%sello worl%s
diff --git a/sapi/cli/tests/bug64544.phpt b/sapi/cli/tests/bug64544.phpt
new file mode 100644
index 000000000..cc49545c1
--- /dev/null
+++ b/sapi/cli/tests/bug64544.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Bug #64544 (Valgrind warnings after using putenv)
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == "WIN") {
+ die("skip non windows test");
+}
+?>
+--FILE--
+<?php
+
+putenv("HOME=/tmp");
+var_dump(getenv("HOME"));
+
+putenv("FOO=BAR");
+var_dump(getenv("FOO"));
+?>
+--EXPECTF--
+string(4) "/tmp"
+string(3) "BAR"