/* C test case for Bug#67225, demonstrates that when: * client connects with UTF8 charset * byte > 7f sent with UNION The data is truncated Setup: use test; create table x (x binary(2)); Verification: run test, then: use test; select hex(x) from x; To run without union change if(1) to if(0) where query string is set. gcc -Iinclude -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1 -o bug bug67225.c -Llib -lmysqlclient -lpthread -lm -lrt -ldl -Wall -ggdb3 && ./bug */ #include #include #include #include #include int main(int argc, char **argv) { MYSQL *conn = mysql_init(NULL); mysql_set_character_set(conn, "utf8"); conn = mysql_real_connect(conn, "127.0.0.1", "root", NULL, "test", 0, NULL, 0); MYSQL_STMT *stmt = mysql_stmt_init(conn); /* using same table from java test */ const char *query; if (1) query = "insert into x select ? union select ?"; else /* works without UNION */ query = "insert into x select ? from (select 1) as x where 1 <> ?"; mysql_stmt_prepare(stmt, query, strlen(query)); MYSQL_BIND *params = malloc(sizeof(MYSQL_BIND) * 2); memset(params, 0, sizeof(MYSQL_BIND) * 2); params[0].buffer_type = MYSQL_TYPE_VAR_STRING; /* works w/MYSQL_TYPE_BLOB */ params[0].buffer = malloc(2); char *b = params[0].buffer; b[0] = 0x50; b[1] = 0x80; params[0].buffer_length = 2; params[0].is_unsigned = 1; /* no effect */ memcpy(¶ms[1], ¶ms[0], sizeof(MYSQL_BIND)); mysql_stmt_bind_param(stmt, params); mysql_stmt_execute(stmt); printf("Ok\n"); return 0; }