Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: korablev@tarantool.org, tsafin@tarantool.org,
	tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v5 06/17] sql: check args of char()
Date: Tue, 14 Jul 2020 18:48:24 +0300	[thread overview]
Message-ID: <9526e2942a2d94fed1b89204c17e30253ae8d2de.1594741192.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1594741192.git.imeevma@gmail.com>

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

  parent reply	other threads:[~2020-07-14 15:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-14 15:48 [Tarantool-patches] [PATCH v5 00/17] sql: change implicit cast for assignment imeevma
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 01/17] sql: set field_type in mem_set_*() functions imeevma
2020-07-15 12:22   ` Nikita Pettik
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 02/17] sql: change implicit cast for assignment imeevma
2020-07-15 13:41   ` Mergen Imeev
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 03/17] sql: use ApplyType to check function arguments imeevma
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 04/17] sql: check args of abs() imeevma
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 05/17] sql: check args of avg(), sum() and total() imeevma
2020-07-14 15:48 ` imeevma [this message]
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 07/17] sql: check args of length() imeevma
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 08/17] sql: check operands of LIKE imeevma
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 09/17] sql: check args of lower() and upper() imeevma
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 10/17] sql: check args of position() imeevma
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 11/17] sql: check args of randomblob() imeevma
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 12/17] sql: check args of replace() imeevma
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 13/17] sql: check args of round() imeevma
2020-07-14 15:48 ` [Tarantool-patches] [PATCH v5 14/17] sql: check args of soundex() imeevma
2020-07-14 15:49 ` [Tarantool-patches] [PATCH v5 15/17] sql: check args of substr() imeevma
2020-07-14 15:49 ` [Tarantool-patches] [PATCH v5 16/17] sql: check args of unicode() imeevma
2020-07-14 15:49 ` [Tarantool-patches] [PATCH v5 17/17] sql: check args of zeroblob() imeevma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9526e2942a2d94fed1b89204c17e30253ae8d2de.1594741192.git.imeevma@gmail.com \
    --to=imeevma@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=tsafin@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v5 06/17] sql: check args of char()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox