Skip to content

Commit 6960567

Browse files
committed
Only allow list arrays
1 parent 83f58e0 commit 6960567

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

ext/mysqli/mysqli_api.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,11 @@ PHP_FUNCTION(mysqli_stmt_execute)
830830
unsigned int param_count;
831831
MYSQLND_PARAM_BIND *params;
832832

833+
if (!zend_array_is_list(input_params)) {
834+
zend_argument_value_error(ERROR_ARG_POS(2), "must be a list array");
835+
RETURN_THROWS();
836+
}
837+
833838
hash_num_elements = zend_hash_num_elements(input_params);
834839
param_count = mysql_stmt_param_count(stmt->stmt);
835840
if (hash_num_elements != param_count) {

ext/mysqli/tests/mysqli_stmt_execute_bind.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,13 @@ if (!stristr(mysqli_get_client_info(), 'mysqlnd')) {
125125
assert($stmt->get_result()->fetch_assoc() === ['label'=>'a', 'anon'=>null, 'num' => null]);
126126
$stmt = null;
127127

128-
// 12. array keys are ignored. Even numerical indices are not considered (PDO does a weird thing with the numerical indices)
128+
// 12. Only list arrays are allowed
129129
$stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?');
130-
$stmt->execute(['A'=>'abc', 2=>42, null=>$id]);
131-
assert($stmt->get_result()->fetch_assoc() === ['label'=>'a', 'anon'=>'abc', 'num' => '42']);
130+
try {
131+
$stmt->execute(['A'=>'abc', 2=>42, null=>$id]);
132+
} catch (ValueError $e) {
133+
echo '[008] '.$e->getMessage()."\n";
134+
}
132135
$stmt = null;
133136

134137

@@ -147,4 +150,5 @@ if (!stristr(mysqli_get_client_info(), 'mysqlnd')) {
147150
[005] mysqli_stmt::execute(): Argument #1 ($params) must be of type ?array, int given
148151
[006] mysqli_stmt::execute(): Argument #1 ($params) must be of type ?array, stdClass given
149152
[007] mysqli_stmt::execute(): Argument #1 ($params) must consist of exactly 3 elements, 0 present
153+
[008] mysqli_stmt::execute(): Argument #1 ($params) must be a list array
150154
done!

0 commit comments

Comments
 (0)