Permalink
Browse files

The possible crash on manipulating constants having length less than …

…two characters was eliminated.

Functions manipulating constants were corrected to work in PHP5.4, new tests were added.
  • Loading branch information...
1 parent 7f5b7b1 commit f6a620a43c031b04ed853ec79b6d339d226bfe11 @zenovich committed Sep 17, 2012
Showing with 64 additions and 3 deletions.
  1. +4 −2 package.xml
  2. +1 −1 php_runkit.h
  3. +12 −0 runkit_constants.c
  4. +47 −0 tests/runkit_constants_manipulations_and_cache.phpt
View
@@ -38,12 +38,13 @@ Execute code in restricted environment (sandboxing).
Critical fixes:
* Crash on sandbox creation when register_globals is switched on was fixed
* Building and working with PHP4 were fixed
+ * Crash on syntax error in source file importing with runkit_import was fixed
+ * The possible crash on manipulating constants having length less than two characters was eliminated
Fixes:
- * Crash on syntax error in source file importing with runkit_import was fixed
* All ways of adding and removing magic methods and old-style constructors
were reworked and corrected (Thanks to Anthony Dovgal for issue #35).
- * Side affect of redefining, adding and removing class constant (Issue #25) was fixed
+ * Side effect of redefining, adding and removing class constant (Issue #25) was eliminated
* Adding of non-lowercase default properties was fixed (removed lowercasing)
* Skip the leading slash in class names
* Copying of functions was reworked
@@ -80,6 +81,7 @@ Execute code in restricted environment (sandboxing).
<file name="runkit_constant_redefine_in_class.phpt" role="test" />
<file name="runkit_constant_remove.phpt" role="test" />
<file name="runkit_constant_remove_from_class.phpt" role="test" />
+ <file name="runkit_constants_manipulations_and_cache.phpt" role="test" />
<file name="runkit_function_redefine_and_revert.phpt" role="test" />
<file name="runkit_function_add.phpt" role="test" />
<file name="runkit_function_copy.phpt" role="test" />
View
@@ -326,7 +326,7 @@ struct _php_runkit_sandbox_object {
#define PHP_RUNKIT_SPLIT_PN(classname, classname_len, pnname, pnname_len) { \
char *colon; \
\
- if ((colon = memchr((pnname), ':', (pnname_len) - 2)) && (colon[1] == ':')) { \
+ if ((pnname_len) > 3 && (colon = memchr((pnname), ':', (pnname_len) - 2)) && (colon[1] == ':')) { \
(classname) = (pnname); \
(classname_len) = colon - (classname); \
(pnname) = colon + 2; \
View
@@ -110,6 +110,9 @@ static int php_runkit_constant_remove(char *classname, int classname_len, char *
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to remove constant %s::%s", classname, constname);
return FAILURE;
}
+#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION > 5)
+ php_runkit_clear_all_functions_runtime_cache(TSRMLS_C);
+#endif
return SUCCESS;
#else
/* PHP4 doesn't support class constants */
@@ -153,6 +156,11 @@ static int php_runkit_constant_remove(char *classname, int classname_len, char *
if (lcase) {
efree(lcase);
}
+
+#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION > 5)
+ php_runkit_clear_all_functions_runtime_cache(TSRMLS_C);
+#endif
+
return SUCCESS;
}
/* }}} */
@@ -218,6 +226,10 @@ static int php_runkit_constant_add(char *classname, int classname_len, char *con
return FAILURE;
}
+#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION > 5)
+ php_runkit_clear_all_functions_runtime_cache(TSRMLS_C);
+#endif
+
zend_hash_apply_with_arguments(RUNKIT_53_TSRMLS_PARAM(EG(class_table)), (apply_func_args_t)php_runkit_update_children_consts, 4, ce, copyval, constname, constname_len);
return SUCCESS;
@@ -0,0 +1,47 @@
+--TEST--
+Test for caching issues on manipulations with constants
+--SKIPIF--
+<?php
+ if(!extension_loaded("runkit") || !RUNKIT_FEATURE_MANIPULATION) print "skip";
+ if(array_shift(explode('.', PHP_VERSION)) < 5) print "skip";
+?>
+--INI--
+error_reporting=E_ALL
+display_errors=on
+--FILE--
+<?php
+define('A', 0);
+class RunkitClass {
+ const A = 0;
+}
+
+class Test {
+ function a($result) {
+ for ($i = 0; $i < 10; $i++) {
+ runkit_constant_redefine('RunkitClass::A', RunkitClass::A+1);
+ $result = RunkitClass::A;
+ runkit_constant_remove('RunkitClass::A');
+ runkit_constant_add('RunkitClass::A', $result+1);
+ runkit_constant_redefine('A', A+1);
+ $result = A;
+ runkit_constant_remove('A');
+ runkit_constant_add('A', $result+1);
+ }
+ return A;
+ }
+
+ function t() {
+ $result = 0;
+ for ($i = 0; $i < 10; $i++) {
+ $result = $this->a($result);
+ }
+ echo "" . A . "\n";
+ echo "" . RunkitClass::A . "\n";
+ }
+}
+
+$t = new Test();
+$t->t();
+--EXPECT--
+200
+200

0 comments on commit f6a620a

Please sign in to comment.