From 3be5897c3346639fa6d7195480d93108798c4917 Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Thu, 12 Mar 2020 12:06:40 +0100 Subject: [PATCH] Fix for MDEV-21920 when converting (or copying) from string empty string weren't handled correctly. This was a regression error, introduced by a prior covscan fix. --- libmariadb/ma_stmt_codec.c | 2 +- unittest/libmariadb/ps_bugs.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/libmariadb/ma_stmt_codec.c b/libmariadb/ma_stmt_codec.c index 300e7ac05..d38fbd259 100644 --- a/libmariadb/ma_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -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; diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index 7af447cc2..1ea218d6e 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -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},