Skip to content

Commit ec56650

Browse files
committed
PDO MySQL: Check number of bounds params even if none are bound
The check for the number of bound parameters was only executed if at least one was bound. We should also error if nothing was bound. With mysqlnd, mysqlnd itself ended up emitting an error, but with libmysqlclient this error condition would not be detected.
1 parent 7ba0c74 commit ec56650

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

ext/pdo_mysql/mysql_statement.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,15 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt) /* {{{ */
315315
S->done = 0;
316316

317317
if (S->stmt) {
318+
uint32_t num_bound_params =
319+
stmt->bound_params ? zend_hash_num_elements(stmt->bound_params) : 0;
320+
if (num_bound_params < (uint32_t) S->num_params) {
321+
/* too few parameter bound */
322+
PDO_DBG_ERR("too few parameters bound");
323+
strcpy(stmt->error_code, "HY093");
324+
PDO_DBG_RETURN(0);
325+
}
326+
318327
PDO_DBG_RETURN(pdo_mysql_stmt_execute_prepared(stmt));
319328
}
320329

@@ -403,13 +412,6 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
403412
PDO_DBG_RETURN(1);
404413

405414
case PDO_PARAM_EVT_EXEC_PRE:
406-
if (zend_hash_num_elements(stmt->bound_params) < (unsigned int) S->num_params) {
407-
/* too few parameter bound */
408-
PDO_DBG_ERR("too few parameters bound");
409-
strcpy(stmt->error_code, "HY093");
410-
PDO_DBG_RETURN(0);
411-
}
412-
413415
if (!Z_ISREF(param->parameter)) {
414416
parameter = &param->parameter;
415417
} else {

ext/pdo_mysql/tests/bug81037.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ require __DIR__ . '/mysql_pdo_test.inc';
3232
MySQLPDOTest::dropTestTable();
3333
?>
3434
--EXPECT--
35-
SQLSTATE[HY000]: General error: 2031 No data supplied for parameters in prepared statement
35+
SQLSTATE[HY093]: Invalid parameter number

0 commit comments

Comments
 (0)