diff --git a/libmariadb/net.c b/libmariadb/net.c index 0cae5054..134322e0 100644 --- a/libmariadb/net.c +++ b/libmariadb/net.c @@ -41,6 +41,7 @@ See bug conc-57 */ #undef net_buffer_length + #undef max_allowed_packet ulong max_allowed_packet=1024L * 1024L * 1024L; ulong net_read_timeout= NET_READ_TIMEOUT; @@ -113,9 +114,9 @@ int my_net_init(NET *net, Vio* vio) { if (!(net->buff=(uchar*) my_malloc(net_buffer_length,MYF(MY_WME | MY_ZEROFILL)))) return 1; - if (net_buffer_length > max_allowed_packet) - max_allowed_packet=net_buffer_length; - net->max_packet_size= 0xFFFFFF; +// if (net_buffer_length > max_allowed_packet) +// max_allowed_packet=net_buffer_length; + max_allowed_packet= net->max_packet_size= MAX(net_buffer_length, max_allowed_packet); net->buff_end=net->buff+(net->max_packet=net_buffer_length); net->vio = vio; net->error=0; net->return_status=0; @@ -654,8 +655,7 @@ my_real_read(NET *net, size_t *complen) /* The necessary size of net->buff */ if (helping >= net->max_packet) { - /* We must allocate one extra byte for the end null */ - if (net_realloc(net,helping + 1)) + if (net_realloc(net,helping)) { #ifdef MYSQL_SERVER if (i == 1) @@ -699,6 +699,7 @@ ulong my_net_read(NET *net) { length+= len; net->where_b+= (unsigned long)len; + len= my_real_read(net, &complen); } while (len == MAX_PACKET_LENGTH); net->where_b= last_pos; if (len != packet_error) diff --git a/unittest/libmariadb/basic-t.c b/unittest/libmariadb/basic-t.c index 014c8680..c3c08f8a 100644 --- a/unittest/libmariadb/basic-t.c +++ b/unittest/libmariadb/basic-t.c @@ -30,6 +30,72 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "my_test.h" #include "ma_common.h" +static int test_conc68(MYSQL *mysql) +{ + int rc; + MYSQL_RES *res; + MYSQL_ROW row; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a LONGBLOB)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (REPEAT('A', 1024 * 1024 * 20))"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT a FROM t1"); + check_mysql_rc(rc, mysql); + + if (!(res= mysql_store_result(mysql))) + { + diag("Error: %s", mysql_error(mysql)); + return FAIL; + } + + row= mysql_fetch_row(res); + FAIL_IF(strlen(row[0]) != 1024 * 1024 * 20, "Wrong length"); + mysql_free_result(res); + + return OK; +} + +static int test_conc66(MYSQL *my) +{ + MYSQL *mysql= mysql_init(NULL); + int rc; + FILE *fp; + + fp= fopen("./my.cnf", "w"); + fprintf(fp, "[conc-66]\nuser=conc-66\npassword=\"my#pass;word\""); + fclose(fp); + + rc= mysql_query(my, "GRANT ALL ON test.* to 'conc-66'@'%' identified by 'my#pass;word'"); + check_mysql_rc(rc, mysql); + rc= mysql_query(my, "FLUSH PRIVILEGES"); + check_mysql_rc(rc, mysql); + + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "conc-66"); + check_mysql_rc(rc, mysql); + rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my.cnf"); + check_mysql_rc(rc, mysql); + + rc= mysql_real_connect(mysql, hostname, NULL, NULL, schema, + port, socketname, 0); + if (!rc) { + diag("Error: %s\n", mysql_error(mysql)); + mysql_close(mysql); + return FAIL; + } + mysql_close(mysql); + + rc= mysql_query(my, "DROP USER 'conc-66'"); + check_mysql_rc(rc, mysql); + + return OK; +} + static int basic_connect(MYSQL *mysql) { MYSQL_ROW row; @@ -555,6 +621,8 @@ static int test_compressed(MYSQL *my) } struct my_tests_st my_tests[] = { + {"test_conc68", test_conc68, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, + {"test_conc66", test_conc66, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_compressed", test_compressed, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"test_reconnect_maxpackage", test_reconnect_maxpackage, TEST_CONNECTION_NONE, 0, NULL, NULL}, {"basic_connect", basic_connect, TEST_CONNECTION_NONE, 0, NULL, NULL},