Skip to content
Browse files

An accidental wiping of superglobals in PHP5.4 have been eliminated, …

…a new test was added (issue #39)
  • Loading branch information...
1 parent 16ee30a commit b8c9cfa1c8d521b8272e92e4f45328ceca96017d @zenovich committed
Showing with 35 additions and 7 deletions.
  1. +1 −0 package.xml
  2. +15 −7 runkit.c
  3. +19 −0 tests/runkit_and_superglobals.phpt
View
1 package.xml
@@ -79,6 +79,7 @@ Execute code in restricted environment (sandboxing).
<file name="runkit_add_old_style_ctor_by_importing.inc" role="test" />
<file name="runkit_add_old_style_ctor_by_importing.phpt" role="test" />
<file name="runkit_adopt_emancipate_and_inheritance.phpt" role="test" />
+ <file name="runkit_and_superglobals.phpt" role="test" />
<file name="runkit_class_adopt.phpt" role="test" />
<file name="runkit_class_emancipate.phpt" role="test" />
<file name="runkit_constant_add.phpt" role="test" />
View
22 runkit.c
@@ -290,6 +290,10 @@ PHP_MSHUTDOWN_FUNCTION(runkit)
Register an autoglobal only if it's not already registered */
static void php_runkit_register_auto_global(char *s, int len TSRMLS_DC)
{
+#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION >= 6)
+ zend_auto_global *auto_global;
+#endif
+
if (zend_hash_exists(CG(auto_globals), s, len + 1)) {
/* Registered already */
return;
@@ -297,21 +301,25 @@ static void php_runkit_register_auto_global(char *s, int len TSRMLS_DC)
#ifdef ZEND_ENGINE_2
if (zend_register_auto_global(s, len,
-#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION >= 6)
+# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION >= 6)
0,
-#endif
+# endif
NULL TSRMLS_CC) == SUCCESS) {
-#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION >= 6)
- zend_activate_auto_globals(TSRMLS_C);
-#else
+# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION >= 6)
+ if (zend_hash_find(CG(auto_globals), s, len + 1, (void *) &auto_global) != SUCCESS) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot locate the newly created autoglobal");
+ return;
+ }
+ auto_global->armed = 0;
+# else
/* This shouldn't be necessary, but it is */
zend_auto_global_disable_jit(s, len TSRMLS_CC);
-#endif
+# endif
#else
if (zend_register_auto_global(s, len TSRMLS_CC) == SUCCESS) {
-#endif
+#endif // ZEND_ENGINE_2
if (!RUNKIT_G(superglobals)) {
ALLOC_HASHTABLE(RUNKIT_G(superglobals));
View
19 tests/runkit_and_superglobals.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Superglobals should not be wiped by runkit
+--SKIPIF--
+<?php
+if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip";
+?>
+--INI--
+error_reporting=E_ALL
+display_errors=on
+runkit.superglobal=_POST,_REQUEST,my
+--POST--
+TEST=test
+--FILE--
+<?php
+echo $_POST['TEST'], "\n";
+echo $_REQUEST['TEST'], "\n";
+--EXPECT--
+test
+test

0 comments on commit b8c9cfa

Please sign in to comment.
Something went wrong with that request. Please try again.