Skip to content

Commit

Permalink
Fix for MDEV-21920
Browse files Browse the repository at this point in the history
when converting (or copying) from string empty string weren't handled
correctly. This was a regression error, introduced by a prior covscan fix.
  • Loading branch information
9EOR9 committed Mar 12, 2020
1 parent f9a5046 commit 3be5897
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libmariadb/ma_stmt_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ static void convert_froma_string(MYSQL_BIND *r_param, char *buffer, size_t len)
case MYSQL_TYPE_NEWDECIMAL:
default:
{
if (len > r_param->offset)
if (len >= r_param->offset)
{
char *start= buffer + r_param->offset; /* stmt_fetch_column sets offset */
char *end= buffer + len;
Expand Down
35 changes: 35 additions & 0 deletions unittest/libmariadb/ps_bugs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5161,7 +5161,42 @@ static int test_maxparam(MYSQL *mysql)
return OK;
}

static int test_mdev_21920(MYSQL *mysql)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
MYSQL_BIND bind[1];
int rc;
char buffer[128];

rc= mysql_stmt_prepare(stmt, SL("SELECT ''"));
check_stmt_rc(rc, stmt);

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

buffer[0]= 1;

memset(bind, 0, sizeof(MYSQL_BIND));
bind[0].buffer_type= MYSQL_TYPE_STRING;
bind[0].buffer= buffer;
bind[0].buffer_length= 127;

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

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

FAIL_IF(buffer[0] != 0, "Expected empty string");


mysql_stmt_close(stmt);

return OK;
}

struct my_tests_st my_tests[] = {
{"test_mdev_21920", test_mdev_21920, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_maxparam", test_maxparam, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_conc424", test_conc424, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_conc344", test_conc344, TEST_CONNECTION_NEW, 0, NULL, NULL},
Expand Down

0 comments on commit 3be5897

Please sign in to comment.