Skip to content

Commit 592b232

Browse files
committed
Fix bug #63173: Crash when invoking invalid array callback
The code did not check whether the zend_hash_index_find calls succeded, so PHP crashed when an array callback was called that contains two elements which don't have the indices 0 and 1.
1 parent 8cdd6bc commit 592b232

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Zend/tests/bug63173.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #63173: Crash when invoking invalid array callback
3+
--FILE--
4+
<?php
5+
6+
// the important part here are the indexes 1 and 2
7+
$callback = [1 => 0, 2 => 0];
8+
$callback();
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Array callback has to contain indices 0 and 1 in %s on line %d

Zend/zend_vm_def.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,10 @@ ZEND_VM_HANDLER(59, ZEND_INIT_FCALL_BY_NAME, ANY, CONST|TMP|VAR|CV)
24122412
zend_hash_index_find(Z_ARRVAL_P(function_name), 0, (void **) &obj);
24132413
zend_hash_index_find(Z_ARRVAL_P(function_name), 1, (void **) &method);
24142414

2415+
if (!obj || !method) {
2416+
zend_error_noreturn(E_ERROR, "Array callback has to contain indices 0 and 1");
2417+
}
2418+
24152419
if (Z_TYPE_PP(obj) != IS_STRING && Z_TYPE_PP(obj) != IS_OBJECT) {
24162420
zend_error_noreturn(E_ERROR, "First array member is not a valid class name or object");
24172421
}

Zend/zend_vm_execute.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,10 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_CONST_HANDLER(ZEND_OPCODE
12561256
zend_hash_index_find(Z_ARRVAL_P(function_name), 0, (void **) &obj);
12571257
zend_hash_index_find(Z_ARRVAL_P(function_name), 1, (void **) &method);
12581258

1259+
if (!obj || !method) {
1260+
zend_error_noreturn(E_ERROR, "Array callback has to contain indices 0 and 1");
1261+
}
1262+
12591263
if (Z_TYPE_PP(obj) != IS_STRING && Z_TYPE_PP(obj) != IS_OBJECT) {
12601264
zend_error_noreturn(E_ERROR, "First array member is not a valid class name or object");
12611265
}
@@ -1558,6 +1562,10 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_TMP_HANDLER(ZEND_OPCODE_H
15581562
zend_hash_index_find(Z_ARRVAL_P(function_name), 0, (void **) &obj);
15591563
zend_hash_index_find(Z_ARRVAL_P(function_name), 1, (void **) &method);
15601564

1565+
if (!obj || !method) {
1566+
zend_error_noreturn(E_ERROR, "Array callback has to contain indices 0 and 1");
1567+
}
1568+
15611569
if (Z_TYPE_PP(obj) != IS_STRING && Z_TYPE_PP(obj) != IS_OBJECT) {
15621570
zend_error_noreturn(E_ERROR, "First array member is not a valid class name or object");
15631571
}
@@ -1722,6 +1730,10 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_VAR_HANDLER(ZEND_OPCODE_H
17221730
zend_hash_index_find(Z_ARRVAL_P(function_name), 0, (void **) &obj);
17231731
zend_hash_index_find(Z_ARRVAL_P(function_name), 1, (void **) &method);
17241732

1733+
if (!obj || !method) {
1734+
zend_error_noreturn(E_ERROR, "Array callback has to contain indices 0 and 1");
1735+
}
1736+
17251737
if (Z_TYPE_PP(obj) != IS_STRING && Z_TYPE_PP(obj) != IS_OBJECT) {
17261738
zend_error_noreturn(E_ERROR, "First array member is not a valid class name or object");
17271739
}
@@ -1919,6 +1931,10 @@ static int ZEND_FASTCALL ZEND_INIT_FCALL_BY_NAME_SPEC_CV_HANDLER(ZEND_OPCODE_HA
19191931
zend_hash_index_find(Z_ARRVAL_P(function_name), 0, (void **) &obj);
19201932
zend_hash_index_find(Z_ARRVAL_P(function_name), 1, (void **) &method);
19211933

1934+
if (!obj || !method) {
1935+
zend_error_noreturn(E_ERROR, "Array callback has to contain indices 0 and 1");
1936+
}
1937+
19221938
if (Z_TYPE_PP(obj) != IS_STRING && Z_TYPE_PP(obj) != IS_OBJECT) {
19231939
zend_error_noreturn(E_ERROR, "First array member is not a valid class name or object");
19241940
}

0 commit comments

Comments
 (0)