From 20fbb3c3b967bb4e8325636c72f06aae1f121bcd Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Mon, 29 Apr 2024 10:57:12 +0200 Subject: [PATCH] Avoid possible crash if connection was closed Before checking pending result sets in prepared statements, we need to check if the connection was already closed or resetted by checking stmt->mysql. In case of NULL we return false, since there are no more pending result sets. --- libmariadb/mariadb_stmt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index 4f99ab01..cbf88eed 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -127,7 +127,12 @@ void stmt_set_error(MYSQL_STMT *stmt, pending result set */ static my_bool madb_have_pending_results(MYSQL_STMT *stmt) { - LIST *li_stmt= stmt->mysql->stmts; + LIST *li_stmt; + + if (!stmt->mysql) + return 0; + + li_stmt= stmt->mysql->stmts; for (;li_stmt;li_stmt= li_stmt->next) { MYSQL_STMT *s= (MYSQL_STMT *)li_stmt->data;