Skip to content

Commit

Permalink
The possible crash on manipulating constants having length less than …
Browse files Browse the repository at this point in the history
…two characters was eliminated.

Functions manipulating constants were corrected to work in PHP5.4, new tests were added.
  • Loading branch information
zenovich committed Sep 17, 2012
1 parent 7f5b7b1 commit f6a620a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
6 changes: 4 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" />
Expand Down
2 changes: 1 addition & 1 deletion php_runkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
12 changes: 12 additions & 0 deletions runkit_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}
/* }}} */
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 47 additions & 0 deletions tests/runkit_constants_manipulations_and_cache.phpt
Original file line number Diff line number Diff line change
@@ -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.