From c70fc7d97859ee14052e56adb3f8263a2ab3aa4c Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 22 Jan 2023 23:03:53 +0000 Subject: [PATCH] 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 99fb0154b4bfa..a159da87578de 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -1513,7 +1513,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 ba79b53ab5ba0..c0206328085da 100644 --- a/ext/mysqli/tests/mysqli_stmt_data_seek.phpt +++ b/ext/mysqli/tests/mysqli_stmt_data_seek.phpt @@ -27,6 +27,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)) @@ -87,6 +92,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)