From 23d4dc1627d051f7ddd55e525e121d23656a2fe9 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 22 Jan 2023 23:03:53 +0000 Subject: [PATCH 1/4] Throw error when mysql_stmt_data_seek fails --- ext/mysqli/mysqli_api.c | 5 ++++- ext/mysqli/tests/mysqli_stmt_data_seek.phpt | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index ccb1da6af738..9b62cf662e23 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -1488,7 +1488,10 @@ PHP_FUNCTION(mysqli_stmt_data_seek) MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID); - mysql_stmt_data_seek(stmt->stmt, offset); + if (mysql_stmt_data_seek(stmt->stmt, offset)) { + zend_throw_error(NULL, "The result set buffer is empty"); + RETURN_THROWS(); + } } /* }}} */ diff --git a/ext/mysqli/tests/mysqli_stmt_data_seek.phpt b/ext/mysqli/tests/mysqli_stmt_data_seek.phpt index a36daebc7951..1d57f158936f 100644 --- a/ext/mysqli/tests/mysqli_stmt_data_seek.phpt +++ b/ext/mysqli/tests/mysqli_stmt_data_seek.phpt @@ -25,6 +25,11 @@ require_once 'skipifconnectfailure.inc'; if (true !== ($tmp = mysqli_stmt_execute($stmt))) printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); + try { + mysqli_stmt_data_seek($stmt, 1); + } catch (Error $exception) { + echo $exception->getMessage() . "\n"; + } $id = null; if (!mysqli_stmt_bind_result($stmt, $id)) @@ -82,6 +87,7 @@ require_once 'skipifconnectfailure.inc'; ?> --EXPECT-- mysqli_stmt object is not fully initialized +The result set buffer is empty int(3) int(1) int(1) From 89b34394d964189888d02e69f6ff8a6d56766d3d Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 21 Apr 2026 14:34:18 +0100 Subject: [PATCH 2/4] Check ahead of time --- ext/mysqli/mysqli_api.c | 6 ++++-- ext/mysqli/tests/mysqli_stmt_data_seek.phpt | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 9b62cf662e23..5f4b9fcd18ca 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -1488,10 +1488,12 @@ PHP_FUNCTION(mysqli_stmt_data_seek) MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID); - if (mysql_stmt_data_seek(stmt->stmt, offset)) { - zend_throw_error(NULL, "The result set buffer is empty"); + if (!stmt->stmt->data || !stmt->stmt->data->result || !stmt->stmt->data->result->stored_data) { + zend_throw_error(NULL, "No result set associated with the statement"); RETURN_THROWS(); } + + mysql_stmt_data_seek(stmt->stmt, offset); } /* }}} */ diff --git a/ext/mysqli/tests/mysqli_stmt_data_seek.phpt b/ext/mysqli/tests/mysqli_stmt_data_seek.phpt index 1d57f158936f..787c87c47c2b 100644 --- a/ext/mysqli/tests/mysqli_stmt_data_seek.phpt +++ b/ext/mysqli/tests/mysqli_stmt_data_seek.phpt @@ -87,7 +87,7 @@ require_once 'skipifconnectfailure.inc'; ?> --EXPECT-- mysqli_stmt object is not fully initialized -The result set buffer is empty +No result set associated with the statement int(3) int(1) int(1) From 418a954f2249bbc0e10ae53156f85f532ffbe9b5 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 21 Apr 2026 17:18:42 +0100 Subject: [PATCH 3/4] Add function name to the message --- ext/mysqli/mysqli_api.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 5f4b9fcd18ca..c667712f85fe 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -1489,7 +1489,11 @@ PHP_FUNCTION(mysqli_stmt_data_seek) MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID); if (!stmt->stmt->data || !stmt->stmt->data->result || !stmt->stmt->data->result->stored_data) { - zend_throw_error(NULL, "No result set associated with the statement"); + if (hasThis()) { + zend_throw_error(NULL, "mysqli_stmt::data_seek(): No result set associated with the statement"); + } else { + zend_throw_error(NULL, "mysqli_stmt_data_seek(): No result set associated with the statement"); + } RETURN_THROWS(); } From 618cd414c2995c9445e970565dd2d5e5d54e4f9d Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Tue, 21 Apr 2026 18:03:29 +0100 Subject: [PATCH 4/4] Fix test case --- ext/mysqli/tests/mysqli_stmt_data_seek.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/mysqli/tests/mysqli_stmt_data_seek.phpt b/ext/mysqli/tests/mysqli_stmt_data_seek.phpt index 787c87c47c2b..e4b913229cd0 100644 --- a/ext/mysqli/tests/mysqli_stmt_data_seek.phpt +++ b/ext/mysqli/tests/mysqli_stmt_data_seek.phpt @@ -87,7 +87,7 @@ require_once 'skipifconnectfailure.inc'; ?> --EXPECT-- mysqli_stmt object is not fully initialized -No result set associated with the statement +mysqli_stmt_data_seek(): No result set associated with the statement int(3) int(1) int(1)