From 895235815cb6743d209f29081831ab1e1c5481fc Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Mon, 16 Jan 2023 11:13:00 +0100 Subject: [PATCH] Fix for CONC-627: Don't substitute parameters in server error messages in prepeated statement error handler function. --- libmariadb/mariadb_stmt.c | 9 +++++++++ unittest/libmariadb/ps_bugs.c | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index cb273bea..74e2f49b 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -106,6 +106,15 @@ void stmt_set_error(MYSQL_STMT *stmt, } } + /* Fix for CONC-627: If this is a server error message, we don't + need to substitute and possible variadic arguments will be + ignored */ + if (!IS_MYSQL_ERROR(error_nr) && !IS_MARIADB_ERROR(error_nr)) + { + strncpy(stmt->last_error, format, MYSQL_ERRMSG_SIZE - 1); + return; + } + va_start(ap, format); vsnprintf(stmt->last_error, MYSQL_ERRMSG_SIZE - 1, format ? format : errmsg, ap); diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index 10507c2d..447dd764 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -5487,7 +5487,28 @@ static int test_mdev19838(MYSQL *mysql) return OK; } +static int test_conc627(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + + rc= mysql_stmt_prepare(stmt, SL("show grants for mysqltest_8")); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_store_result(stmt); + FAIL_IF(!mysql_stmt_errno(stmt), "Expected error"); + FAIL_IF(strcmp(mysql_error(mysql), mysql_stmt_error(stmt)), "Error messages differ"); + + mysql_stmt_close(stmt); + + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc627", test_conc627, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_mdev19838", test_mdev19838, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc566", test_conc566, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc512", test_conc512, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},