From 8dce8dba85b17a57905605e291a2bb33f6d3c64d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 7 Nov 2024 07:34:12 +0200 Subject: [PATCH] CONC-741: Check that MYSQL_STMT is not null The code now again allows null MYSQL_STMT handles to be passed to mysql_stmt_close(). Added a sanity check test case that should guard against this happening in the future. --- libmariadb/mariadb_stmt.c | 2 +- unittest/libmariadb/misc.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index cb37359e..215863ec 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -129,7 +129,7 @@ static my_bool madb_have_pending_results(MYSQL_STMT *stmt) { LIST *li_stmt; - if (!stmt->mysql) + if (!stmt || !stmt->mysql) return 0; li_stmt= stmt->mysql->stmts; diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index 136ffc62..628db2b9 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -1662,6 +1662,13 @@ static int test_disable_tls1_0(MYSQL *my __attribute__((unused))) return OK; } +static int test_null_handles(MYSQL *) +{ + mysql_close(NULL); + mysql_stmt_close(NULL); + return OK; +} + struct my_tests_st my_tests[] = { {"test_disable_tls1_0", test_disable_tls1_0, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, @@ -1707,7 +1714,8 @@ struct my_tests_st my_tests[] = { {"test_ldi_path", test_ldi_path, TEST_CONNECTION_NEW, 0, NULL, NULL}, #ifdef _WIN32 {"test_conc44", test_conc44, TEST_CONNECTION_NEW, 0, NULL, NULL}, -#endif +#endif + {"test_null_handles", test_null_handles, TEST_CONNECTION_NONE, 0, NULL, NULL}, {NULL, NULL, 0, 0, NULL, 0} };