You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-08 14:02:17 +03:00
Fixed conversion from zerofill integer to MYSQL_TYPE_STRING:
if the length of the provided result buffer is equal or smaller than the converted number and ZEROFILL FLAG is set, a truncation error will be reported.
This commit is contained in:
@@ -644,21 +644,27 @@ static void convert_from_long(MYSQL_BIND *r_param, const MYSQL_FIELD *field, lon
|
|||||||
char *buffer;
|
char *buffer;
|
||||||
char *endptr;
|
char *endptr;
|
||||||
uint len;
|
uint len;
|
||||||
|
my_bool zf_truncated= 0;
|
||||||
|
|
||||||
buffer= alloca(MAX(field->length, 22));
|
buffer= alloca(MAX(field->length, 22));
|
||||||
endptr= ma_ll2str(val, buffer, is_unsigned ? 10 : -10);
|
endptr= ma_ll2str(val, buffer, is_unsigned ? 10 : -10);
|
||||||
len= (uint)(endptr - buffer);
|
len= (uint)(endptr - buffer);
|
||||||
|
|
||||||
/* check if field flag is zerofill */
|
/* check if field flag is zerofill */
|
||||||
if (field->flags & ZEROFILL_FLAG &&
|
if (field->flags & ZEROFILL_FLAG)
|
||||||
len < field->length && len < r_param->buffer_length)
|
|
||||||
{
|
{
|
||||||
ma_bmove_upp(buffer + field->length, buffer + len, len);
|
if (len < field->length && len < r_param->buffer_length)
|
||||||
/* coverity [bad_memset] */
|
{
|
||||||
memset((void*) buffer, (int) '0', field->length - len);
|
ma_bmove_upp(buffer + field->length, buffer + len, len);
|
||||||
len= field->length;
|
/* coverity [bad_memset] */
|
||||||
|
memset((void*) buffer, (int) '0', field->length - len);
|
||||||
|
len= field->length;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
zf_truncated= 1;
|
||||||
}
|
}
|
||||||
convert_froma_string(r_param, buffer, len);
|
convert_froma_string(r_param, buffer, len);
|
||||||
|
*r_param->error+= zf_truncated;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -5009,11 +5009,51 @@ static int test_conc_fraction(MYSQL *mysql)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int test_zerofill_1byte(MYSQL *mysql)
|
||||||
|
{
|
||||||
|
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
|
||||||
|
int rc;
|
||||||
|
MYSQL_BIND bind;
|
||||||
|
char buffer[3];
|
||||||
|
|
||||||
|
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
|
||||||
|
rc= mysql_query(mysql, "CREATE TABLE t1 (a int zerofill)");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
|
||||||
|
rc= mysql_query(mysql, "INSERT INTO t1 VALUES(1)");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
|
||||||
|
rc= mysql_stmt_prepare(stmt, SL("SELECT a FROM t1"));
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
rc= mysql_stmt_execute(stmt);
|
||||||
|
check_stmt_rc(rc, stmt);
|
||||||
|
|
||||||
|
memset(&bind, 0, sizeof(MYSQL_BIND));
|
||||||
|
bind.buffer_type= MYSQL_TYPE_STRING;
|
||||||
|
bind.buffer= buffer;
|
||||||
|
bind.buffer_length= 1;
|
||||||
|
|
||||||
|
rc= mysql_stmt_bind_result(stmt, &bind);
|
||||||
|
|
||||||
|
rc= mysql_stmt_fetch(stmt);
|
||||||
|
FAIL_IF(rc != 101, "expected truncation warning");
|
||||||
|
|
||||||
|
mysql_stmt_close(stmt);
|
||||||
|
rc= mysql_query(mysql, "DROP TABLE t1");
|
||||||
|
check_mysql_rc(rc, mysql);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct my_tests_st my_tests[] = {
|
struct my_tests_st my_tests[] = {
|
||||||
{"test_conc344", test_conc344, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
{"test_conc344", test_conc344, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||||
{"test_conc334", test_conc334, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
{"test_conc334", test_conc334, TEST_CONNECTION_NEW, 0, NULL, NULL},
|
||||||
{"test_compress", test_compress, TEST_CONNECTION_NEW, CLIENT_COMPRESS, NULL, NULL},
|
{"test_compress", test_compress, TEST_CONNECTION_NEW, CLIENT_COMPRESS, NULL, NULL},
|
||||||
|
{"test_zerofill_1byte", test_zerofill_1byte, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_codbc138", test_codbc138, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_codbc138", test_codbc138, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_conc208", test_conc208, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_conc208", test_conc208, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
{"test_mdev14165", test_mdev14165, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
{"test_mdev14165", test_mdev14165, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
|
Reference in New Issue
Block a user