From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 1CE90445325 for ; Thu, 16 Jul 2020 17:45:52 +0300 (MSK) From: imeevma@tarantool.org Date: Thu, 16 Jul 2020 17:45:51 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v6 05/22] sql: check args of char() List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: korablev@tarantool.org, tsafin@tarantool.org, tarantool-patches@dev.tarantool.org After this patch, the argument types of the char() function will be checked properly. Part of #4159 --- src/box/sql/func.c | 13 +++++----- test/sql-tap/func5.test.lua | 51 ++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index ed972fdab..2d0aea801 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1454,10 +1454,11 @@ charFunc(sql_context * context, int argc, sql_value ** argv) for (i = 0; i < argc; i++) { uint64_t x; unsigned c; - if (sql_value_type(argv[i]) == MP_INT) - x = 0xfffd; - else - x = sql_value_uint64(argv[i]); + enum mp_type mp_type = sql_value_type(argv[i]); + if (mp_type == MP_NIL) + continue; + assert(mp_type == MP_UINT); + x = sql_value_uint64(argv[i]); if (x > 0x10ffff) x = 0xfffd; c = (unsigned)(x & 0x1fffff); @@ -2264,8 +2265,8 @@ static struct { }, { .name = "CHAR", .param_count = -1, - .first_arg = FIELD_TYPE_ANY, - .args = FIELD_TYPE_ANY, + .first_arg = FIELD_TYPE_UNSIGNED, + .args = FIELD_TYPE_UNSIGNED, .is_blob_like_str = false, .returns = FIELD_TYPE_STRING, .is_deterministic = true, diff --git a/test/sql-tap/func5.test.lua b/test/sql-tap/func5.test.lua index 467ba7292..6e65b98ac 100755 --- a/test/sql-tap/func5.test.lua +++ b/test/sql-tap/func5.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(50) +test:plan(57) --!./tcltestrunner.lua -- 2010 August 27 @@ -493,4 +493,53 @@ test:do_catchsql_test( 1, "Type mismatch: can not convert varbinary to number" }) +test:do_execsql_test( + "func-5-6.5.1", [[ + SELECT char(NULL); + ]],{ + "" + }) + +test:do_execsql_test( + "func-5-6.5.2", [[ + SELECT char(0x33); + ]], { + "3" + }) + +test:do_catchsql_test( + "func-5-6.5.3", [[ + SELECT char(-123); + ]], { + 1, "Type mismatch: can not convert -123 to unsigned" + }) + +test:do_catchsql_test( + "func-5-6.5.4", [[ + SELECT char(-5.5); + ]], { + 1, "Type mismatch: can not convert -5.5 to unsigned" + }) + +test:do_catchsql_test( + "func-5-6.5.5", [[ + SELECT char('-123'); + ]], { + 1, "Type mismatch: can not convert -123 to unsigned" + }) + +test:do_catchsql_test( + "func-5-6.5.6", [[ + SELECT char(false); + ]], { + 1, "Type mismatch: can not convert FALSE to unsigned" + }) + +test:do_catchsql_test( + "func-5-6.5.7", [[ + SELECT char(X'3334'); + ]], { + 1, "Type mismatch: can not convert varbinary to unsigned" + }) + test:finish_test() -- 2.25.1