Skip to content
Browse files

merged branch arnaud-lb/807 (PR #812)

Commits
-------

3ca6654 avoid crash when TWIG_GET_ARRAY_ELEMENT returns NULL
3694d4b allow --EXCEPTION-- tests to have a --DATA-- block

Discussion
----------

Fix for #807 (Segmentation fault when exception thrown inside any of ArrayAccess implementation methods)

This fixes #807
  • Loading branch information...
2 parents 3e4057b + 3ca6654 commit 552143062982fd15a1d6fe5a0cdda1f007212154 @fabpot committed Aug 20, 2012
Showing with 12 additions and 3 deletions.
  1. +3 −0 ext/twig/twig.c
  2. +9 −3 test/Twig/Tests/integrationTest.php
View
3 ext/twig/twig.c
@@ -713,6 +713,9 @@ PHP_FUNCTION(twig_template_get_attributes)
}
ret = TWIG_GET_ARRAY_ELEMENT(object, item, item_len TSRMLS_CC);
+ if (!ret) {
+ ret = &EG(uninitialized_zval);
+ }
RETVAL_ZVAL(ret, 1, 0);
if (free_ret) {
zval_ptr_dtor(&ret);
View
12 test/Twig/Tests/integrationTest.php
@@ -31,12 +31,12 @@ public function getTests()
$test = file_get_contents($file->getRealpath());
if (preg_match('/
- --TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*))+)\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) {
+ --TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)\s*(?:--DATA--\s*(.*))?\s*--EXCEPTION--\s*(.*)/sx', $test, $match)) {
$message = $match[1];
$condition = $match[2];
$templates = $this->parseTemplates($match[3]);
- $exception = $match[4];
- $outputs = array(null, array(), null, '');
+ $exception = $match[5];
+ $outputs = array(array(null, $match[4], null, ''));
} elseif (preg_match('/--TEST--\s*(.*?)\s*(?:--CONDITION--\s*(.*))?\s*((?:--TEMPLATE(?:\(.*?\))?--(?:.*?))+)--DATA--.*?--EXPECT--.*/s', $test, $match)) {
$message = $match[1];
$condition = $match[2];
@@ -114,6 +114,12 @@ public function testIntegration($file, $message, $condition, $templates, $except
$output = trim(sprintf('%s: %s', get_class($e), $e->getMessage()));
}
+
+ if (false !== $exception) {
+ list($class, ) = explode(':', $exception);
+ $this->assertThat(NULL, new PHPUnit_Framework_Constraint_Exception($class));
+ }
+
$expected = trim($match[3], "\n ");
if ($expected != $output) {

0 comments on commit 5521430

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