com php-src: Ensure symtable exists before checking it: ext/standard/tests/strings/parse_str_memory_error.phpt main/php_variables.c
| From: | Nikita Popov | Date: | Wed, 28 Sep 2016 17:20:17 +0000 |
| Subject: | com php-src: Ensure symtable exists before checking it: ext/standard/tests/strings/parse_str_memory_error.phpt main/php_variables.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94732@lists.php.net to get a copy of this message | ||
Commit: 4c0804c07de703826e38646bb6cc6d6ca633ddc4
Author: Nikita Popov <nikic@php.net> Wed, 28 Sep 2016 19:19:31 +0200
Parents: e5d75d72688fb047ab1dbc7b19e51fe4a3dc0fc9
Branches: PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=4c0804c07de703826e38646bb6cc6d6ca633ddc4
Log:
Ensure symtable exists before checking it
Changed paths:
A ext/standard/tests/strings/parse_str_memory_error.phpt
M main/php_variables.c
Diff:
diff --git a/ext/standard/tests/strings/parse_str_memory_error.phpt
b/ext/standard/tests/strings/parse_str_memory_error.phpt
new file mode 100644
index 0000000..0242d97
--- /dev/null
+++ b/ext/standard/tests/strings/parse_str_memory_error.phpt
@@ -0,0 +1,19 @@
+--TEST--
+parse_str() should not read uninitialized memory when checking for $this
+--FILE--
+<?php
+
+function test() {
+ // strlen("abcd") == 4 is relevant
+ parse_str('abcd=1', $array);
+ var_dump($array);
+}
+
+test();
+
+?>
+--EXPECT--
+array(1) {
+ ["abcd"]=>
+ string(1) "1"
+}
diff --git a/main/php_variables.c b/main/php_variables.c
index 7f0823a..a5256e7 100644
--- a/main/php_variables.c
+++ b/main/php_variables.c
@@ -114,7 +114,8 @@ PHPAPI void php_register_variable_ex(char *var_name, zval *val, zval *track_vars
while (ex) {
if (ex->func && ZEND_USER_CODE(ex->func->common.type)) {
- if (ex->symbol_table == symtable1) {
+ if ((ZEND_CALL_INFO(ex) & ZEND_CALL_HAS_SYMBOL_TABLE)
+ && ex->symbol_table == symtable1) {
if (memcmp(var, "this", sizeof("this")-1) == 0) {
zend_throw_error(NULL, "Cannot re-assign $this");
zval_dtor(val);