summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2017-05-02 14:28:57 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2017-05-02 14:28:57 +0400
commit42ad4f2821112be4e7bb4ca6d407cc72f9df6f8d (patch)
treee5a18f18bd7b772595cfd05ad729ee6c812b7170
parent7afcee4cf66c73ae3f9c5f04763b4b7a1d37e419 (diff)
downloadmariadb-git-42ad4f2821112be4e7bb4ca6d407cc72f9df6f8d.tar.gz
MDEV-12364 Server crashes in __memcpy_sse2_unaligned / String::copy on
JSON_SEARCH with variables. Wrong index for the tmp_paths array in Item_func_json_search::val_str.
-rw-r--r--mysql-test/r/func_json.result4
-rw-r--r--mysql-test/t/func_json.test7
-rw-r--r--sql/item_jsonfunc.cc2
3 files changed, 12 insertions, 1 deletions
diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result
index eff8f5c9c92..cc682a0756d 100644
--- a/mysql-test/r/func_json.result
+++ b/mysql-test/r/func_json.result
@@ -629,3 +629,7 @@ j p json_remove(j, p)
{"a":1,"b":2,"c":3} $.b {"a": 1, "c": 3}
{"a":1,"b":2,"c":3} $.c {"a": 1, "b": 2}
drop table t1;
+SET @str = 'bar', @path = '$';
+SELECT JSON_SEARCH('{"foo":"bar"}', 'all' , @str, '%', @path);
+JSON_SEARCH('{"foo":"bar"}', 'all' , @str, '%', @path)
+"$.foo"
diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test
index 72b8681ac44..7ff5f3f13d9 100644
--- a/mysql-test/t/func_json.test
+++ b/mysql-test/t/func_json.test
@@ -274,3 +274,10 @@ insert into t1 values
('{"a":1,"b":2,"c":3}','$.c');
select j, p, json_remove(j, p) from t1;
drop table t1;
+
+#
+# MDEV-12364 Server crashes in __memcpy_sse2_unaligned / String::copy on JSON_SEARCH with variables.
+#
+SET @str = 'bar', @path = '$';
+SELECT JSON_SEARCH('{"foo":"bar"}', 'all' , @str, '%', @path);
+
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc
index b8471dc8244..caacd189664 100644
--- a/sql/item_jsonfunc.cc
+++ b/sql/item_jsonfunc.cc
@@ -2898,7 +2898,7 @@ String *Item_func_json_search::val_str(String *str)
json_path_with_flags *c_path= paths + n_arg - 4;
if (!c_path->parsed)
{
- String *s_p= args[n_arg]->val_str(tmp_paths + (n_arg-1));
+ String *s_p= args[n_arg]->val_str(tmp_paths + (n_arg-4));
if (s_p &&
json_path_setup(&c_path->p,s_p->charset(),(const uchar *) s_p->ptr(),
(const uchar *) s_p->ptr() + s_p->length()))