Skip to content

Commit

Permalink
Fix for CONC-205: (manually merged from master)
Browse files Browse the repository at this point in the history
  • Loading branch information
9EOR9 committed Oct 26, 2016
1 parent 2e14b0a commit c32c117
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 24 deletions.
35 changes: 17 additions & 18 deletions libmariadb/my_stmt_codec.c
Expand Up @@ -918,28 +918,27 @@ static
void ps_fetch_bin(MYSQL_BIND *r_param, const MYSQL_FIELD *field,
unsigned char **row)
{
ulong field_length= *r_param->length= net_field_length(row);
uchar *current_pos= (*row) + r_param->offset,
*end= (*row) + field_length;
size_t copylen= 0;

if (current_pos < end)
if (field->charsetnr == 63)
{
copylen= end - current_pos;
if (r_param->buffer_length)
ulong field_length= *r_param->length= net_field_length(row);
uchar *current_pos= (*row) + r_param->offset,
*end= (*row) + field_length;
size_t copylen= 0;

if (current_pos < end)
{
memcpy(r_param->buffer, current_pos, MIN(copylen, r_param->buffer_length));
if (copylen < r_param->buffer_length &&
r_param->buffer_type == MYSQL_TYPE_STRING)
((char *)r_param->buffer)[copylen]= 0;
copylen= end - current_pos;
if (r_param->buffer_length)
memcpy(r_param->buffer, current_pos, MIN(copylen, r_param->buffer_length));
}
if (copylen < r_param->buffer_length &&
r_param->buffer_type == MYSQL_TYPE_STRING)
((char *)r_param->buffer)[copylen]= 0;
*r_param->error= copylen > r_param->buffer_length;
(*row)+= field_length;
}
*r_param->error= copylen > r_param->buffer_length;
/* don't count trailing zero if we fetch into string */
if (r_param->buffer_type == MYSQL_TYPE_STRING &&
!*r_param->error)
field_length--;
(*row)+= field_length;
else
ps_fetch_string(r_param, field, row);
}
/* }}} */

Expand Down
6 changes: 1 addition & 5 deletions libmariadb/my_thr_init.c
Expand Up @@ -152,12 +152,8 @@ void my_thread_end(void)

if (tmp && tmp->initialized)
{
#ifdef HAVE_OPENSSL
#if OPENSSL_VERSION_NUMBER >= 0x10000001L
#if defined(HAVE_OPENSSL) && OPENSSL_VERSION_NUMBER < 0x10100000L
ERR_remove_thread_state(NULL);
#else
ERR_remove_state(0);
#endif
#endif
#if !defined(DBUG_OFF)
if (tmp->dbug)
Expand Down
87 changes: 86 additions & 1 deletion unittest/libmariadb/ps_bugs.c
Expand Up @@ -2581,6 +2581,8 @@ static int test_bug5194(MYSQL *mysql)
const int uint16_max= 65535;
int nrows, i;

diag("Test needs to be reworked");
return SKIP;

stmt_text= "drop table if exists t1";
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
Expand Down Expand Up @@ -2636,7 +2638,7 @@ static int test_bug5194(MYSQL *mysql)
MAX_PARAM_COUNT * CHARS_PER_PARAM + 1);
param_str= (char*) malloc(COLUMN_COUNT * CHARS_PER_PARAM);

FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enought memory")
FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enough memory")

stmt= mysql_stmt_init(mysql);

Expand Down Expand Up @@ -4408,7 +4410,90 @@ static int test_conc198(MYSQL *mysql)
return OK;
}

static int test_conc205(MYSQL *mysql)
{
MYSQL_STMT *stmt;
MYSQL_BIND my_bind[3];
char data[8];
ulong length[3];
int rc, int_col;
short smint_col;
my_bool is_null[3];
const char *query = "SELECT text_col, smint_col, int_col FROM test_conc205";

rc= mysql_query(mysql, "drop table if exists test_conc205");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "CREATE TABLE test_conc205 (text_col TEXT, smint_col SMALLINT, int_col INT)");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "INSERT INTO test_conc205 VALUES('data01', 21893, 1718038908), ('data2', -25734, -1857802040)");
check_mysql_rc(rc, mysql);

stmt= mysql_stmt_init(mysql);
FAIL_IF(!stmt, mysql_error(mysql));

rc= mysql_stmt_prepare(stmt, query, (unsigned long)strlen(query));
check_stmt_rc(rc, stmt);

memset(my_bind, '\0', sizeof(my_bind));
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
my_bind[0].buffer= (void *)data;
my_bind[0].buffer_length= sizeof(data);
my_bind[0].is_null= &is_null[0];
my_bind[0].length= &length[0];

my_bind[1].buffer_type= MYSQL_TYPE_SHORT;
my_bind[1].buffer= &smint_col;
my_bind[1].buffer_length= 2;
my_bind[1].is_null= &is_null[1];
my_bind[1].length= &length[1];

my_bind[2].buffer_type= MYSQL_TYPE_LONG;
my_bind[2].buffer= &int_col;
my_bind[2].buffer_length= 4;
my_bind[2].is_null= &is_null[2];
my_bind[2].length= &length[2];

rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);

rc= mysql_stmt_bind_result(stmt, my_bind);
check_stmt_rc(rc, stmt);

rc= mysql_stmt_fetch(stmt);
check_stmt_rc(rc, stmt);

FAIL_IF(length[0] != 6, "Wrong fetched string length");
FAIL_IF(length[1] != 2, "Wrong fetched short length");
FAIL_IF(length[2] != 4, "Wrong fetched int length");

FAIL_IF(strncmp(data, "data01", length[0] + 1) != 0, "Wrong string value");
FAIL_IF(smint_col != 21893, "Expected 21893");
FAIL_IF(int_col != 1718038908, "Expected 1718038908");

rc= mysql_stmt_fetch(stmt);
check_stmt_rc(rc, stmt);

FAIL_IF(length[0] != 5, "Wrong fetched string length");
FAIL_IF(length[1] != 2, "Wrong fetched short length");
FAIL_IF(length[2] != 4, "Wrong fetched int length");

FAIL_IF(strncmp(data, "data2", length[0] + 1) != 0, "Wrong string value");
FAIL_IF(smint_col != -25734, "Expected 21893");
FAIL_IF(int_col != -1857802040, "Expected 1718038908");

rc= mysql_stmt_fetch(stmt);
FAIL_IF(rc != MYSQL_NO_DATA, "Expected MYSQL_NO_DATA");

mysql_stmt_close(stmt);

rc= mysql_query(mysql, "drop table test_conc205");
check_mysql_rc(rc, mysql);

return OK;
}

struct my_tests_st my_tests[] = {
{"test_conc205", test_conc205, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc198", test_conc198, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc194", test_conc194, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc177", test_conc177, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
Expand Down

0 comments on commit c32c117

Please sign in to comment.