@@ -710,6 +710,7 @@ PHP_FUNCTION(twig_template_get_attributes)
710710 char * class_name = NULL ;
711711 zval * tmp_class ;
712712 char * type_name ;
713+ zval * propertySandboxException ;
713714
714715 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ozz|asbb" , & template , & object , & zitem , & arguments , & type , & type_len , & isDefinedTest , & ignoreStrictCheck ) == FAILURE ) {
715716 return ;
@@ -917,10 +918,15 @@ PHP_FUNCTION(twig_template_get_attributes)
917918 }
918919
919920 if ($this->env->hasExtension('sandbox')) {
920- $this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item);
921+ try {
922+ $this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item);
923+ } catch (Twig_Sandbox_SecurityError $propertySandboxException) {
924+ }
921925 }
922926
923- return $object->$item;
927+ if (!isset($propertySandboxException)) {
928+ return $object->$item;
929+ }
924930 }
925931 }
926932*/
@@ -938,14 +944,17 @@ PHP_FUNCTION(twig_template_get_attributes)
938944 if (TWIG_CALL_SB (TWIG_PROPERTY_CHAR (template , "env" TSRMLS_CC ), "hasExtension" , "sandbox" TSRMLS_CC )) {
939945 TWIG_CALL_ZZ (TWIG_CALL_S (TWIG_PROPERTY_CHAR (template , "env" TSRMLS_CC ), "getExtension" , "sandbox" TSRMLS_CC ), "checkPropertyAllowed" , object , zitem TSRMLS_CC );
940946 }
941- if (EG (exception )) {
947+ if (EG (exception ) && TWIG_INSTANCE_OF_USERLAND (EG (exception ), "Twig_Sandbox_SecurityError" TSRMLS_CC )) {
948+ propertySandboxException = EG (exception );
949+ EG (exception ) = NULL ;
950+ } else if (EG (exception )) {
942951 efree (item );
943952 return ;
953+ } else {
954+ ret = TWIG_PROPERTY (object , zitem TSRMLS_CC );
955+ efree (item );
956+ RETURN_ZVAL (ret , 1 , 0 );
944957 }
945-
946- ret = TWIG_PROPERTY (object , zitem TSRMLS_CC );
947- efree (item );
948- RETURN_ZVAL (ret , 1 , 0 );
949958 }
950959 }
951960/*
@@ -1016,6 +1025,10 @@ PHP_FUNCTION(twig_template_get_attributes)
10161025 return false;
10171026 }
10181027
1028+ if (isset($propertySandboxException)) {
1029+ throw $propertySandboxException;
1030+ }
1031+
10191032 if ($ignoreStrictCheck || !$this->env->isStrictVariables()) {
10201033 return null;
10211034 }
@@ -1036,6 +1049,11 @@ PHP_FUNCTION(twig_template_get_attributes)
10361049 efree (item );
10371050 RETURN_FALSE ;
10381051 }
1052+ if (Z_TYPE_P (propertySandboxException ) == IS_OBJECT ) {
1053+ efree (item );
1054+ EG (exception ) = propertySandboxException ;
1055+ return ;
1056+ }
10391057 if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN (TWIG_PROPERTY_CHAR (template , "env" TSRMLS_CC ), "isStrictVariables" TSRMLS_CC )) {
10401058 efree (item );
10411059 return ;
@@ -1053,11 +1071,15 @@ PHP_FUNCTION(twig_template_get_attributes)
10531071 }
10541072/*
10551073 if ($this->env->hasExtension('sandbox')) {
1056- $this->env->getExtension('sandbox')->checkMethodAllowed($object, $method);
1074+ $this->env->getExtension('sandbox')->checkMethodAllowed($object, $call ? '__call' : $ method);
10571075 }
10581076*/
10591077 MAKE_STD_ZVAL (zmethod );
1060- ZVAL_STRING (zmethod , method , 1 );
1078+ if (call ) {
1079+ ZVAL_STRING (zmethod , "__call" , 1 );
1080+ } else {
1081+ ZVAL_STRING (zmethod , method , 1 );
1082+ }
10611083 if (TWIG_CALL_SB (TWIG_PROPERTY_CHAR (template , "env" TSRMLS_CC ), "hasExtension" , "sandbox" TSRMLS_CC )) {
10621084 TWIG_CALL_ZZ (TWIG_CALL_S (TWIG_PROPERTY_CHAR (template , "env" TSRMLS_CC ), "getExtension" , "sandbox" TSRMLS_CC ), "checkMethodAllowed" , object , zmethod TSRMLS_CC );
10631085 }
@@ -1074,26 +1096,32 @@ PHP_FUNCTION(twig_template_get_attributes)
10741096 try {
10751097 $ret = call_user_func_array(array($object, $method), $arguments);
10761098 } catch (BadMethodCallException $e) {
1077- if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) {
1078- return null;
1079- }
1080- throw $e;
1099+ if ($call && isset($propertySandboxException)) {
1100+ throw $propertySandboxException;
1101+ }
1102+
1103+ if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) {
1104+ return null;
1105+ }
1106+ throw $e;
10811107 }
10821108*/
10831109 ret = TWIG_CALL_USER_FUNC_ARRAY (object , method , arguments TSRMLS_CC );
1084- if (EG (exception ) && TWIG_INSTANCE_OF (EG (exception ), spl_ce_BadMethodCallException TSRMLS_CC )) {
1110+ efree (tmp_method_name_get );
1111+ efree (tmp_method_name_is );
1112+ efree (lcItem );
1113+ if (call && EG (exception ) && TWIG_INSTANCE_OF (EG (exception ), spl_ce_BadMethodCallException TSRMLS_CC )) {
1114+ if (Z_TYPE_P (propertySandboxException ) == IS_OBJECT ) {
1115+ efree (item );
1116+ EG (exception ) = propertySandboxException ;
1117+ return ;
1118+ }
10851119 if (ignoreStrictCheck || !TWIG_CALL_BOOLEAN (TWIG_PROPERTY_CHAR (template , "env" TSRMLS_CC ), "isStrictVariables" TSRMLS_CC )) {
1086- efree (tmp_method_name_get );
1087- efree (tmp_method_name_is );
1088- efree (lcItem );efree (item );
10891120 zend_clear_exception (TSRMLS_C );
10901121 return ;
10911122 }
10921123 }
10931124 free_ret = 1 ;
1094- efree (tmp_method_name_get );
1095- efree (tmp_method_name_is );
1096- efree (lcItem );
10971125 }
10981126/*
10991127 // useful when calling a template method from a template
0 commit comments