From 6e800d8277280b2aebc4ff13787e47d6f6940d79 Mon Sep 17 00:00:00 2001 From: Tugdual Saunier Date: Thu, 13 Feb 2014 09:35:20 +0000 Subject: [PATCH] Fixed fetching of a property defined but not initialized in C extension, fixed #1337 --- CHANGELOG | 1 + ext/twig/twig.c | 6 ++---- test/Twig/Tests/TemplateTest.php | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cbc8805..7a4c3a3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ * fixed the conversion of the special '0000-00-00 00:00' date * added an error message when trying to import an undefined block from a trait + * fixed a C extension crash when accessing defined but uninitialized property. * 1.15.0 (2013-12-06) diff --git a/ext/twig/twig.c b/ext/twig/twig.c index a36f192..5cb923f 100644 --- a/ext/twig/twig.c +++ b/ext/twig/twig.c @@ -324,10 +324,8 @@ zval *TWIG_PROPERTY(zval *object, zval *propname TSRMLS_DC) #else tmp = Z_OBJ_HT_P(object)->read_property(object, propname, BP_VAR_IS TSRMLS_CC); #endif - if (tmp != EG(uninitialized_zval_ptr)) { - return tmp; - } else { - return NULL; + if (tmp == EG(uninitialized_zval_ptr)) { + ZVAL_NULL(tmp); } } return tmp; diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 34b7a63..aa8dafd 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -268,6 +268,7 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase $propertyObject = new Twig_TemplatePropertyObject(); $propertyObject1 = new Twig_TemplatePropertyObjectAndIterator(); $propertyObject2 = new Twig_TemplatePropertyObjectAndArrayAccess(); + $propertyObject3 = new Twig_TemplatePropertyObjectDefinedWithUndefinedValue(); $methodObject = new Twig_TemplateMethodObject(); $magicMethodObject = new Twig_TemplateMagicMethodObject(); @@ -317,6 +318,11 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase } } + // additional properties tests + $tests = array_merge($tests, array( + array(true, null, $propertyObject3, 'foo', array(), $anyType), + )); + // additional method tests $tests = array_merge($tests, array( array(true, 'defined', $methodObject, 'defined', array(), $methodType), @@ -545,6 +551,16 @@ class Twig_TemplatePropertyObjectAndArrayAccess extends Twig_TemplatePropertyObj } } +class Twig_TemplatePropertyObjectDefinedWithUndefinedValue +{ + public $foo; + + public function __construct() + { + $this->foo = @$notExist; + } +} + class Twig_TemplateMethodObject { public function getDefined() -- 1.7.2.5