From f50b20b080bf4e4a0ef33e2b612a0819867f65bf Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Mon, 7 Nov 2022 20:22:04 -0500 Subject: [PATCH 1/3] bump the VERSION --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea5e201f..820110e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ SET(CC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) SET(CPACK_PACKAGE_VERSION_MAJOR 3) SET(CPACK_PACKAGE_VERSION_MINOR 1) -SET(CPACK_PACKAGE_VERSION_PATCH 19) +SET(CPACK_PACKAGE_VERSION_PATCH 20) SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") MATH(EXPR MARIADB_PACKAGE_VERSION_ID "${CPACK_PACKAGE_VERSION_MAJOR} * 10000 + ${CPACK_PACKAGE_VERSION_MINOR} * 100 + @@ -172,7 +172,7 @@ IF(MAJOR_VERSION) ELSE() SET(MARIADB_CLIENT_VERSION_MAJOR "10") SET(MARIADB_CLIENT_VERSION_MINOR "5") - SET(MARIADB_CLIENT_VERSION_PATCH "17") + SET(MARIADB_CLIENT_VERSION_PATCH "19") SET(MARIADB_CLIENT_VERSION_EXTRA "") ENDIF() SET(MARIADB_CLIENT_VERSION "${MARIADB_CLIENT_VERSION_MAJOR}.${MARIADB_CLIENT_VERSION_MINOR}.${MARIADB_CLIENT_VERSION_PATCH}${MARIADB_CLIENT_VERSION_EXTRA}") From b9e9758e9373f756ed94aff66fbbbad53ba99009 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Fri, 13 Jan 2023 16:32:03 +0100 Subject: [PATCH 2/3] Fix for CONC-625 Fixed error numbers in comments. --- libmariadb/ma_errmsg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libmariadb/ma_errmsg.c b/libmariadb/ma_errmsg.c index 1dc4633f..dedfd6a7 100644 --- a/libmariadb/ma_errmsg.c +++ b/libmariadb/ma_errmsg.c @@ -140,10 +140,10 @@ const char *client_errors[]= /* 2055 */ "Lost connection to MySQL server at '%s', system error: %d", /* 2056 */ "Server closed statement due to a prior %s function call", /* 2057 */ "The number of parameters in bound buffers differs from number of columns in resultset", -/* 2059 */ "Can't connect twice. Already connected", -/* 2058 */ "Plugin %s could not be loaded: %s", -/* 2059 */ "An attribute with same name already exists", -/* 2060 */ "Plugin doesn't support this function", +/* 2058 */ "Can't connect twice. Already connected", +/* 2059 */ "Plugin %s could not be loaded: %s", +/* 2060 */ "An attribute with same name already exists", +/* 2061 */ "Plugin doesn't support this function", "" }; #endif From bf82b2d8cb83edcd549a7c7bbdfd21a4b5b0a156 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Sun, 15 Jan 2023 14:11:54 +0100 Subject: [PATCH 3/3] Fix for CONC-624: - ER() macro now checks if the error code is known, if not it will return "Unknown or undefined error code" (instead of crashing) - SET_CLIENT_STMT_ERROR now maps to stmt_set_error and accepts variadic arguments --- include/errmsg.h | 15 +++++++++---- include/mariadb_stmt.h | 15 ++++++------- libmariadb/mariadb_lib.c | 24 ++++++++++---------- libmariadb/mariadb_stmt.c | 22 +++++++++++++------ unittest/libmariadb/basic-t.c | 41 +++++++++++++++++++++++++++++++++++ unittest/libmariadb/charset.c | 13 +++++++---- unittest/libmariadb/my_test.h | 1 + 7 files changed, 97 insertions(+), 34 deletions(-) diff --git a/include/errmsg.h b/include/errmsg.h index 8a7a718c..a3d22785 100644 --- a/include/errmsg.h +++ b/include/errmsg.h @@ -31,16 +31,14 @@ extern const char *mariadb_client_errors[]; /* Error messages */ } #endif - - #define CR_MIN_ERROR 2000 /* For easier client code */ #define CR_MAX_ERROR 2999 #define CER_MIN_ERROR 5000 #define CER_MAX_ERROR 5999 -#define CER(X) mariadb_client_errors[(X)-CER_MIN_ERROR] -#define ER(X) client_errors[(X)-CR_MIN_ERROR] #define CLIENT_ERRMAP 2 /* Errormap used by ma_error() */ +#define ER_UNKNOWN_ERROR_CODE "Unknown or undefined error code (%d)" + #define CR_UNKNOWN_ERROR 2000 #define CR_SOCKET_CREATE_ERROR 2001 #define CR_CONNECTION_ERROR 2002 @@ -109,3 +107,12 @@ extern const char *mariadb_client_errors[]; /* Error messages */ value for CR_MARIADB_LAST_ERROR */ #define CR_MARIADB_LAST_ERROR CR_ERR_NET_UNCOMPRESS #endif + +#define IS_MYSQL_ERROR(code) ((code) > CR_MIN_ERROR && (code) < CR_MYSQL_LAST_ERROR) +#define IS_MARIADB_ERROR(code) ((code) > CER_MIN_ERROR && (code) < CR_MARIADB_LAST_ERROR) + +#define ER(code) IS_MYSQL_ERROR((code)) ? client_errors[(code) - CR_MIN_ERROR] : \ + IS_MARIADB_ERROR((code)) ? mariadb_client_errors[(code) - CER_MIN_ERROR] : \ + "Unknown or undefined error code" +#define CER(code) ER((code)) + diff --git a/include/mariadb_stmt.h b/include/mariadb_stmt.h index d07540ea..e25405e8 100644 --- a/include/mariadb_stmt.h +++ b/include/mariadb_stmt.h @@ -34,14 +34,8 @@ ((stmt)->mysql->extension->mariadb_server_capabilities & \ (MARIADB_CLIENT_STMT_BULK_OPERATIONS >> 32)))) -#define SET_CLIENT_STMT_ERROR(a, b, c, d) \ -do { \ - (a)->last_errno= (b);\ - strncpy((a)->sqlstate, (c), SQLSTATE_LENGTH);\ - (a)->sqlstate[SQLSTATE_LENGTH]= 0;\ - strncpy((a)->last_error, (d) ? (d) : ER((b)), MYSQL_ERRMSG_SIZE);\ - (a)->last_error[MYSQL_ERRMSG_SIZE - 1]= 0;\ -} while (0) +#define SET_CLIENT_STMT_ERROR(a, b, c, d, ...) \ + stmt_set_error((a),(b),(c),(d), ##__VA_ARGS__) #define CLEAR_CLIENT_STMT_ERROR(a) \ do { \ @@ -262,6 +256,11 @@ void mysql_init_ps_subsystem(void); unsigned long net_field_length(unsigned char **packet); int ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, size_t length, my_bool skipp_check, void *opt_arg); +void stmt_set_error(MYSQL_STMT *stmt, + unsigned int error_nr, + const char *sqlstate, + const char *format, + ...); /* * function prototypes */ diff --git a/libmariadb/mariadb_lib.c b/libmariadb/mariadb_lib.c index 1d090ec1..f8a3d923 100644 --- a/libmariadb/mariadb_lib.c +++ b/libmariadb/mariadb_lib.c @@ -1851,7 +1851,7 @@ void ma_invalidate_stmts(MYSQL *mysql, const char *function_name) { MYSQL_STMT *stmt= (MYSQL_STMT *)li_stmt->data; stmt->mysql= NULL; - SET_CLIENT_STMT_ERROR(stmt, CR_STMT_CLOSED, SQLSTATE_UNKNOWN, function_name); + SET_CLIENT_STMT_ERROR(stmt, CR_STMT_CLOSED, SQLSTATE_UNKNOWN, 0, function_name); } mysql->stmts= NULL; } @@ -2049,18 +2049,20 @@ void my_set_error(MYSQL *mysql, const char *errmsg; - if (!format) - { - if (error_nr >= CR_MIN_ERROR && error_nr <= CR_MYSQL_LAST_ERROR) - errmsg= ER(error_nr); - else if (error_nr >= CER_MIN_ERROR && error_nr <= CR_MARIADB_LAST_ERROR) - errmsg= CER(error_nr); - else - errmsg= ER(CR_UNKNOWN_ERROR); - } - mysql->net.last_errno= error_nr; ma_strmake(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH); + + if (!format) + { + if (IS_MYSQL_ERROR(error_nr) || IS_MARIADB_ERROR(error_nr)) + errmsg= ER(error_nr); + else { + snprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE - 1, + ER_UNKNOWN_ERROR_CODE, error_nr); + return; + } + } + va_start(ap, format); vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE - 1, format ? format : errmsg, ap); diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c index fe8d35e6..346e46ae 100644 --- a/libmariadb/mariadb_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -89,18 +89,26 @@ void stmt_set_error(MYSQL_STMT *stmt, ...) { va_list ap; - const char *error= NULL; - if (error_nr >= CR_MIN_ERROR && error_nr <= CR_MYSQL_LAST_ERROR) - error= ER(error_nr); - else if (error_nr >= CER_MIN_ERROR && error_nr <= CR_MARIADB_LAST_ERROR) - error= CER(error_nr); + const char *errmsg; stmt->last_errno= error_nr; ma_strmake(stmt->sqlstate, sqlstate, SQLSTATE_LENGTH); + + if (!format) + { + if (IS_MYSQL_ERROR(error_nr) || IS_MARIADB_ERROR(error_nr)) + errmsg= ER(error_nr); + else { + snprintf(stmt->last_error, MYSQL_ERRMSG_SIZE - 1, + ER_UNKNOWN_ERROR_CODE, error_nr); + return; + } + } + va_start(ap, format); - vsnprintf(stmt->last_error, MYSQL_ERRMSG_SIZE, - format ? format : error ? error : "", ap); + vsnprintf(stmt->last_error, MYSQL_ERRMSG_SIZE - 1, + format ? format : errmsg, ap); va_end(ap); return; } diff --git a/unittest/libmariadb/basic-t.c b/unittest/libmariadb/basic-t.c index 87bff9a9..0a4630fc 100644 --- a/unittest/libmariadb/basic-t.c +++ b/unittest/libmariadb/basic-t.c @@ -805,7 +805,48 @@ static int test_compressed(MYSQL *unused __attribute__((unused))) return OK; } +static int test_conc624(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + char errmsg[MYSQL_ERRMSG_SIZE]; + + SET_CLIENT_STMT_ERROR(stmt, 9000, SQLSTATE_UNKNOWN, 0); + snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 9000); + diag("stmt_error: %s", mysql_stmt_error(stmt)); + FAIL_IF(strcmp(mysql_stmt_error(stmt), errmsg), "expected undefined error 9000"); + + SET_CLIENT_STMT_ERROR(stmt, 0, SQLSTATE_UNKNOWN, 0); + snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 0); + FAIL_IF(strcmp(mysql_stmt_error(stmt), errmsg), "expected undefined error 0"); + + SET_CLIENT_STMT_ERROR(stmt, 4999, SQLSTATE_UNKNOWN, 0); + snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 4999); + FAIL_IF(strcmp(mysql_stmt_error(stmt), errmsg), "expected undefined error 4999"); + + my_set_error(mysql, 4999, SQLSTATE_UNKNOWN, 0); + snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 4999); + FAIL_IF(strcmp(mysql_error(mysql), errmsg), "expected undefined error 4999"); + + my_set_error(mysql, 0, SQLSTATE_UNKNOWN, 0); + snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 0); + FAIL_IF(strcmp(mysql_error(mysql), errmsg), "expected undefined error 0"); + + my_set_error(mysql, 9000, SQLSTATE_UNKNOWN, 0); + snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER_UNKNOWN_ERROR_CODE, 9000); + FAIL_IF(strcmp(mysql_error(mysql), errmsg), "expected undefined error 9000"); + + /* test if SET_CLIENT_STMT_ERROR works with variadic arguments */ + SET_CLIENT_STMT_ERROR(stmt, CR_STMT_CLOSED, SQLSTATE_UNKNOWN, 0, "foobar"); + snprintf(errmsg, MYSQL_ERRMSG_SIZE, ER(CR_STMT_CLOSED), "foobar"); + FAIL_IF(strcmp(mysql_stmt_error(stmt), errmsg), "error when passing variadic arguments to prepared stmt error function"); + + mysql_stmt_close(stmt); + + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc624", test_conc624, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc75", test_conc75, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc74", test_conc74, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc71", test_conc71, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, diff --git a/unittest/libmariadb/charset.c b/unittest/libmariadb/charset.c index 6424b94f..6c432749 100644 --- a/unittest/libmariadb/charset.c +++ b/unittest/libmariadb/charset.c @@ -803,11 +803,16 @@ static int test_conc223(MYSQL *mysql) res= mysql_store_result(mysql); while ((row = mysql_fetch_row(res))) { - int id= atoi(row[0]); - if (!mariadb_get_charset_by_nr(id)) + int id; + + if (row[0]) { - diag("%04d %s %s", id, row[1], row[2]); - found++; + id= atoi(row[0]); + if (!mariadb_get_charset_by_nr(id)) + { + diag("%04d %s %s", id, row[1], row[2]); + found++; + } } } mysql_free_result(res); diff --git a/unittest/libmariadb/my_test.h b/unittest/libmariadb/my_test.h index 8b8da62f..a96b6ffb 100644 --- a/unittest/libmariadb/my_test.h +++ b/unittest/libmariadb/my_test.h @@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include +#include #ifndef WIN32 #include