From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 88A40445330 for ; Thu, 16 Jul 2020 17:47:09 +0300 (MSK) From: imeevma@tarantool.org Date: Thu, 16 Jul 2020 17:47:08 +0300 Message-Id: <48a166c6c1138db425c0d447c7dddc1f8e729329.1594909974.git.imeevma@gmail.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v6 16/22] sql: check args of zeroblob() 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 zeroblob() function will be checked properly. Closes #4159 --- src/box/sql/func.c | 9 ++++--- test/sql-tap/func5.test.lua | 50 ++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 00ba7c9c2..5232f6745 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1480,9 +1480,12 @@ zeroblobFunc(sql_context * context, int argc, sql_value ** argv) i64 n; assert(argc == 1); UNUSED_PARAMETER(argc); + enum mp_type mp_type = sql_value_type(argv[0]); + if (mp_type == MP_NIL) + return sql_result_null(context); + assert(mp_type == MP_UINT); n = sql_value_int64(argv[0]); - if (n < 0) - n = 0; + assert(n >= 0); if (sql_result_zeroblob64(context, n) != 0) { diag_set(ClientError, ER_SQL_EXECUTE, "string or binary string"\ "is too big"); @@ -2971,7 +2974,7 @@ static struct { }, { .name = "ZEROBLOB", .param_count = 1, - .first_arg = FIELD_TYPE_ANY, + .first_arg = FIELD_TYPE_UNSIGNED, .args = FIELD_TYPE_ANY, .is_blob_like_str = false, .returns = FIELD_TYPE_VARBINARY, diff --git a/test/sql-tap/func5.test.lua b/test/sql-tap/func5.test.lua index 77105baf2..66ee6782a 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(148) +test:plan(155) --!./tcltestrunner.lua -- 2010 August 27 @@ -1178,5 +1178,53 @@ test:do_catchsql_test( ]], { 1, "Type mismatch: can not convert varbinary to string" }) +test:do_execsql_test( + "func-5-6.13.1", [[ + SELECT zeroblob(NULL); + ]],{ + "" + }) + +test:do_execsql_test( + "func-5-6.13.2", [[ + SELECT zeroblob(3); + ]], { + '\0\0\0' + }) + +test:do_catchsql_test( + "func-5-6.13.3", [[ + SELECT zeroblob(-123); + ]], { + 1, "Type mismatch: can not convert -123 to unsigned" + }) + +test:do_catchsql_test( + "func-5-6.13.4", [[ + SELECT zeroblob(-5.5); + ]], { + 1, "Type mismatch: can not convert -5.5 to unsigned" + }) + +test:do_catchsql_test( + "func-5-6.13.5", [[ + SELECT zeroblob('-123'); + ]], { + 1, "Type mismatch: can not convert -123 to unsigned" + }) + +test:do_catchsql_test( + "func-5-6.13.6", [[ + SELECT zeroblob(false); + ]], { + 1, "Type mismatch: can not convert FALSE to unsigned" + }) + +test:do_catchsql_test( + "func-5-6.13.7", [[ + SELECT zeroblob(X'3334'); + ]], { + 1, "Type mismatch: can not convert varbinary to unsigned" + }) test:finish_test() -- 2.25.1