diff --git a/libmariadb/mariadb_lib.c b/libmariadb/mariadb_lib.c index 1a839415..c1814e8f 100644 --- a/libmariadb/mariadb_lib.c +++ b/libmariadb/mariadb_lib.c @@ -2627,13 +2627,13 @@ mysql_get_client_info(void) static size_t get_store_length(size_t length) { - if (length < (size_t) L64(251)) - return 1; - if (length < (size_t) L64(65536)) - return 2; - if (length < (size_t) L64(16777216)) - return 3; - return 9; + #define MAX_STORE_SIZE 9 + unsigned char buffer[MAX_STORE_SIZE], *p; + + /* We just store the length and substract offset of our buffer + to determine the length */ + p= mysql_net_store_length(buffer, length); + return p - buffer; } uchar *ma_get_hash_keyval(const uchar *hash_entry, diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index b0e53f5c..d30c58f0 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -1325,7 +1325,29 @@ static int test_wl6797(MYSQL *mysql) return OK; } +static int test_conc384(MYSQL *my __attribute__((unused))) +{ + char value[1000]; + int len; + MYSQL *mysql= mysql_init(NULL); + + memset(&value, 'A', 999); + value[999]= 0; + + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo", value); + len= (int)mysql->options.extension->connect_attrs_len; + /* Length: 1 (=len) + 3 (="foo") + 3 (=len) + 999 (="AAA...") = 1006 */ + FAIL_IF(len != 1006, "Wrong length"); + mysql_optionsv(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "foo"); + len= (int)mysql->options.extension->connect_attrs_len; + /* Length should be zero after deleting the connection attribute */ + FAIL_IF(len != 0, "Wrong length"); + mysql_close(mysql); + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc384", test_conc384, TEST_CONNECTION_NONE, 0, NULL, NULL}, #ifndef _WIN32 {"test_mdev12965", test_mdev12965, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, #endif