]> granicus.if.org Git - php/commitdiff
Fix serializing ZEND_AST_SHELL_EXEC
authorSara Golemon <pollita@php.net>
Thu, 12 May 2016 02:28:57 +0000 (02:28 +0000)
committerSara Golemon <pollita@php.net>
Thu, 12 May 2016 02:47:56 +0000 (02:47 +0000)
Currently, `foo` is reserialized as `'foo'` due to misuse of zend_ast_export().
ZEND_AST_SHELL_EXEC can only contain ZEND_AST_ZVAL(string) or ZEND_AST_ENCAPS_LIST,
so just handle the ZEND_AST_ZVAL(string) case directly.

Zend/tests/ast_serialize_backtick_literal.phpt [new file with mode: 0644]
Zend/zend_ast.c

diff --git a/Zend/tests/ast_serialize_backtick_literal.phpt b/Zend/tests/ast_serialize_backtick_literal.phpt
new file mode 100644 (file)
index 0000000..03bdc29
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Serialization of backtick literal is incorrect
+--INI--
+zend.assertions=1
+--FILE--
+<?php
+
+assert_options(ASSERT_WARNING);
+assert(false && `echo -n ""`);
+--EXPECTF--
+Warning: assert(): assert(false && `echo -n ""`) failed in %s/ast_serialize_backtick_literal.php on line 4
index 37728870920906c10b09b371b487eb2527bac6ed..11980f10eeb2587b4b3ff095d852e1d29905d560 100644 (file)
@@ -1217,7 +1217,11 @@ simple_list:
                        if (ast->child[0]->kind == ZEND_AST_ENCAPS_LIST) {
                                zend_ast_export_encaps_list(str, '`', (zend_ast_list*)ast->child[0], indent);
                        } else {
-                               zend_ast_export_ex(str, ast->child[0], 0, indent);
+                               zval *zv;
+                               ZEND_ASSERT(ast->child[0]->kind == ZEND_AST_ZVAL);
+                               zv = zend_ast_get_zval(ast->child[0]);
+                               ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
+                               zend_ast_export_qstr(str, '`', Z_STR_P(zv));
                        }
                        smart_str_appendc(str, '`');
                        break;