Skip to content

Commit

Permalink
Merge pull request #1507 from sjinks/issue-1504
Browse files Browse the repository at this point in the history
Fix #1504
  • Loading branch information
Phalcon committed Nov 3, 2013
2 parents 38e7053 + 176dfdb commit dea1dc2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
17 changes: 13 additions & 4 deletions ext/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,19 @@ static void phalcon_config_write_internal(phalcon_config_object *object, zval *o
{
if (Z_TYPE_P(value) == IS_ARRAY) {
zval *instance;
MAKE_STD_ZVAL(instance);
object_init_ex(instance, phalcon_config_ce);
phalcon_config_construct_internal(instance, value TSRMLS_CC);
phalcon_hash_update_or_insert(object->props, offset, instance);
HashTable *h = Z_ARRVAL_P(value);

if (!h->nApplyCount) {
++h->nApplyCount;
MAKE_STD_ZVAL(instance);
object_init_ex(instance, phalcon_config_ce);
phalcon_config_construct_internal(instance, value TSRMLS_CC);
phalcon_hash_update_or_insert(object->props, offset, instance);
--h->nApplyCount;
}
else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Recursion detected");
}
}
else {
Z_ADDREF_P(value);
Expand Down
12 changes: 12 additions & 0 deletions ext/tests/issue-1504.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Phalcon\Config crashes on recursive arrays - https://github.com/phalcon/cphalcon/issues/1504
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
$a = array();
$a['a'] = &$a;
$c = new \Phalcon\Config($a);
?>
--EXPECTF--
Warning: Phalcon\Config::__construct(): Recursion detected in %s on line %d

0 comments on commit dea1dc2

Please sign in to comment.