1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

Fix for CONC-762: Always set is_null and length in bind structure to avoid

msan errors
This commit is contained in:
Georg Richter
2025-03-31 11:02:35 +02:00
parent f7633e9d68
commit 28a1e4b599
2 changed files with 47 additions and 0 deletions

View File

@@ -414,6 +414,9 @@ int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row)
stmt->bind[i].is_null= &stmt->bind[i].is_null_value; stmt->bind[i].is_null= &stmt->bind[i].is_null_value;
*stmt->bind[i].is_null= 1; *stmt->bind[i].is_null= 1;
stmt->bind[i].u.row_ptr= NULL; stmt->bind[i].u.row_ptr= NULL;
if (!stmt->bind[i].length)
stmt->bind[i].length= &stmt->bind[i].length_value;
*stmt->bind[i].length= stmt->bind[i].length_value= 0;
} }
} else } else
{ {
@@ -426,6 +429,9 @@ int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row)
if (stmt->result_callback) if (stmt->result_callback)
stmt->result_callback(stmt->user_data, i, &row); stmt->result_callback(stmt->user_data, i, &row);
else { else {
if (!stmt->bind[i].is_null)
stmt->bind[i].is_null= &stmt->bind[i].is_null_value;
*stmt->bind[i].is_null= 0;
if (mysql_ps_fetch_functions[stmt->fields[i].type].pack_len >= 0) if (mysql_ps_fetch_functions[stmt->fields[i].type].pack_len >= 0)
length= mysql_ps_fetch_functions[stmt->fields[i].type].pack_len; length= mysql_ps_fetch_functions[stmt->fields[i].type].pack_len;
else else

View File

@@ -5666,8 +5666,49 @@ static int test_conc176(MYSQL *mysql)
return OK; return OK;
} }
static int test_conc762(MYSQL *mysql)
{
int rc;
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
MYSQL_BIND bind[2];
my_bool is_null[2]= {1,1};
unsigned long length[2]= {1,1};
rc= mysql_stmt_prepare(stmt, SL("SELECT NULL, 'foo'"));
check_stmt_rc(rc, stmt);
memset(&bind, 0, sizeof(MYSQL_BIND) * 2);
bind[0].buffer_type = MYSQL_TYPE_STRING;
bind[1].buffer_type = MYSQL_TYPE_STRING;
bind[0].is_null= &is_null[0];
bind[1].is_null= &is_null[1];
bind[0].buffer_length= bind[1].buffer_length= 0;
bind[0].length= &length[0];
bind[1].length= &length[1];
rc= mysql_stmt_execute(stmt);
check_stmt_rc(rc, stmt);
rc= mysql_stmt_bind_result(stmt, bind);
mysql_stmt_fetch(stmt);
FAIL_IF(is_null[0]==0, "Expected NULL value");
FAIL_IF(is_null[1]==1, "Expected non NULL value");
FAIL_IF(length[0]!=0, "Expected length=0");
FAIL_IF(length[1]!=3, "Expected length=3");
// FAIL_IF(length[0] != 0, "Expected length=0");
//FAIL_IF(length[1] != 3, "Expected length=3)";
mysql_stmt_close(stmt);
return OK;
}
struct my_tests_st my_tests[] = { struct my_tests_st my_tests[] = {
{"test_conc762", test_conc762, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc176", test_conc176, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc176", test_conc176, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc739", test_conc739, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc739", test_conc739, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc633", test_conc633, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, {"test_conc633", test_conc633, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},