From 7d3d7c5ff4a9772cf6c73901757d6e39c6a20e99 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 20 Jul 2021 10:55:07 +0200 Subject: [PATCH 1/3] Fix GCC's "ISO C90 forbids mixed declarations and code" --- unittest/libmariadb/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index 4f8e5e34..b95b5d2a 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -1063,9 +1063,9 @@ void *remote_plugin; static int test_remote1(MYSQL *mysql) { int rc; - SKIP_SKYSQL; MYSQL_RES *res; MYSQL_ROW row; + SKIP_SKYSQL; remote_plugin= (void *)mysql_client_find_plugin(mysql, "remote_io", MARIADB_CLIENT_REMOTEIO_PLUGIN); if (!remote_plugin) From 490100ccacedc7aeb89b634fd3f7648a59d096b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 22 Jul 2021 15:55:45 +0300 Subject: [PATCH 2/3] CONC-49 fixup test_conc49(): Do not leak memory. --- unittest/libmariadb/misc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index b95b5d2a..201a981b 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -844,7 +844,10 @@ static int test_conc49(MYSQL *mysql) check_mysql_rc(rc, mysql); res= mysql_store_result(mysql); row= mysql_fetch_row(res); - if (atol(row[0]) == 0) { + + i= !atol(row[0]); + mysql_free_result(res); + if (i) { diag("Load local infile disable"); return SKIP; } From 9c651bd6789e87c9f0daeb05bf2238f5497ea37b Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Mon, 26 Jul 2021 17:47:37 +0200 Subject: [PATCH 3/3] CONC-565: Incorrect max_length in binary protocol Fixed max_length values in ma_stmt_codecs for integer types: - all types included an extra byte for trailing zero character - maximum value for year column type is 2155 (and not 0xFFFF). --- libmariadb/ma_stmt_codec.c | 12 ++++----- unittest/libmariadb/ps.c | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/libmariadb/ma_stmt_codec.c b/libmariadb/ma_stmt_codec.c index 913b6a87..2da04651 100644 --- a/libmariadb/ma_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -1240,27 +1240,27 @@ void mysql_init_ps_subsystem(void) mysql_ps_fetch_functions[MYSQL_TYPE_TINY].func = ps_fetch_int8; mysql_ps_fetch_functions[MYSQL_TYPE_TINY].pack_len = 1; - mysql_ps_fetch_functions[MYSQL_TYPE_TINY].max_len = 4; + mysql_ps_fetch_functions[MYSQL_TYPE_TINY].max_len = 3; mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].func = ps_fetch_int16; mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].pack_len = 2; - mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].max_len = 6; + mysql_ps_fetch_functions[MYSQL_TYPE_SHORT].max_len = 5; mysql_ps_fetch_functions[MYSQL_TYPE_YEAR].func = ps_fetch_int16; mysql_ps_fetch_functions[MYSQL_TYPE_YEAR].pack_len = 2; - mysql_ps_fetch_functions[MYSQL_TYPE_YEAR].max_len = 6; + mysql_ps_fetch_functions[MYSQL_TYPE_YEAR].max_len = 4; mysql_ps_fetch_functions[MYSQL_TYPE_INT24].func = ps_fetch_int32; mysql_ps_fetch_functions[MYSQL_TYPE_INT24].pack_len = 4; - mysql_ps_fetch_functions[MYSQL_TYPE_INT24].max_len = 9; + mysql_ps_fetch_functions[MYSQL_TYPE_INT24].max_len = 8; mysql_ps_fetch_functions[MYSQL_TYPE_LONG].func = ps_fetch_int32; mysql_ps_fetch_functions[MYSQL_TYPE_LONG].pack_len = 4; - mysql_ps_fetch_functions[MYSQL_TYPE_LONG].max_len = 11; + mysql_ps_fetch_functions[MYSQL_TYPE_LONG].max_len = 10; mysql_ps_fetch_functions[MYSQL_TYPE_LONGLONG].func = ps_fetch_int64; mysql_ps_fetch_functions[MYSQL_TYPE_LONGLONG].pack_len= 8; - mysql_ps_fetch_functions[MYSQL_TYPE_LONGLONG].max_len = 21; + mysql_ps_fetch_functions[MYSQL_TYPE_LONGLONG].max_len = 20; mysql_ps_fetch_functions[MYSQL_TYPE_FLOAT].func = ps_fetch_float; mysql_ps_fetch_functions[MYSQL_TYPE_FLOAT].pack_len = 4; diff --git a/unittest/libmariadb/ps.c b/unittest/libmariadb/ps.c index 40ccad6f..58aa6f58 100644 --- a/unittest/libmariadb/ps.c +++ b/unittest/libmariadb/ps.c @@ -5118,7 +5118,59 @@ static int test_conc349(MYSQL *mysql) return OK; } +static int test_conc565(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + MYSQL_FIELD *fields_binary, *fields_text; + MYSQL_RES *result; + int rc; + my_bool x=1; + my_bool error= 0; + + rc= mysql_query(mysql, "CREATE TEMPORARY TABLE t1 (a year, b tinyint unsigned, c smallint unsigned, d mediumint unsigned, e int unsigned, f bigint unsigned)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (2020, 127, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF)"); + check_mysql_rc(rc, mysql); + + rc= mysql_stmt_prepare(stmt, "select a,b,c,d,e,f from t1", -1); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void *)&x); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + + mysql_stmt_store_result(stmt); + fields_binary= mariadb_stmt_fetch_fields(stmt); + + rc= mysql_query(mysql, "SELECT a,b,c,d,e,f FROM t1"); + result= mysql_store_result(mysql); + fields_text= mysql_fetch_fields(result); + + for (unsigned int i=0; i < mysql_field_count(mysql); i++) + { + if (fields_binary[i].length != fields_text[i].length || + fields_binary[i].max_length != fields_text[i].max_length) + { + diag("Sizes differ for column %d (type= %d)", i, fields_binary[i].type); + diag("Binary (length=%ld max_length=%ld) != Text(length=%ld max_length=%ld", + fields_binary[i].length, fields_binary[i].max_length, + fields_text[i].length, fields_text[i].max_length); + error= 1; + goto end; + } + } +end: + mysql_free_result(result); + mysql_stmt_close(stmt); + + return error ? FAIL : OK; +} + struct my_tests_st my_tests[] = { + {"test_conc565", test_conc565, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc349", test_conc349, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_prepare_error", test_prepare_error, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_reexecute", test_reexecute, TEST_CONNECTION_NEW, 0, NULL, NULL},