summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikic@php.net>2016-09-28 22:36:36 +0200
committerNikita Popov <nikic@php.net>2016-09-28 22:36:58 +0200
commit437942d972c15e17539e9029205a1198bb597b90 (patch)
tree9bee592db5c1d650d6e9c7c0301b68ded34e0c28
parentb7cbaa7f43d8a584e273e214209a4f7406a30029 (diff)
parent99bf19c177e272676c363565f5f7b7281a5f1acd (diff)
downloadphp-git-437942d972c15e17539e9029205a1198bb597b90.tar.gz
Merge branch 'PHP-5.6' into PHP-7.0
-rw-r--r--Zend/tests/array_literal_next_element_error.phpt16
-rw-r--r--Zend/zend_vm_def.h5
-rw-r--r--Zend/zend_vm_execute.h80
3 files changed, 84 insertions, 17 deletions
diff --git a/Zend/tests/array_literal_next_element_error.phpt b/Zend/tests/array_literal_next_element_error.phpt
new file mode 100644
index 0000000000..59ffeb02c7
--- /dev/null
+++ b/Zend/tests/array_literal_next_element_error.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Next free element may overflow in array literals
+--FILE--
+<?php
+
+$i = PHP_INT_MAX;
+$array = [$i => 42, new stdClass];
+var_dump($array);
+
+?>
+--EXPECTF--
+Warning: Cannot add element to the array as the next element is already occupied in %s on line %d
+array(1) {
+ [%d]=>
+ int(42)
+}
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 504bf5783b..dcd460ad5d 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -5232,7 +5232,10 @@ ZEND_VM_C_LABEL(num_index):
}
FREE_OP2();
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index b6375908b0..4bc72bd24f 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -6077,7 +6077,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -7891,7 +7894,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -9771,7 +9777,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -11545,7 +11554,10 @@ num_index:
}
zval_ptr_dtor_nogc(free_op2);
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -13014,7 +13026,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -13738,7 +13753,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -14287,7 +14305,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -14801,7 +14822,10 @@ num_index:
}
zval_ptr_dtor_nogc(free_op2);
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -17906,7 +17930,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -19492,7 +19519,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -21077,7 +21107,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -22666,7 +22699,10 @@ num_index:
}
zval_ptr_dtor_nogc(free_op2);
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -32341,7 +32377,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -34874,7 +34913,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -37439,7 +37481,10 @@ num_index:
}
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
@@ -40032,7 +40077,10 @@ num_index:
}
zval_ptr_dtor_nogc(free_op2);
} else {
- zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr);
+ if (!zend_hash_next_index_insert(Z_ARRVAL_P(EX_VAR(opline->result.var)), expr_ptr)) {
+ zend_error(E_WARNING, "Cannot add element to the array as the next element is already occupied");
+ zval_ptr_dtor(expr_ptr);
+ }
}
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}