Skip to content

Commit 4ad0813

Browse files
author
Alexey Botchkov
committed
MDEV-11143 Server crashes in json_string_set_cs.
Some JSON functions didn't expect NULL as a path.
1 parent e8c4195 commit 4ad0813

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

mysql-test/r/func_json.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ json_contains_path('{"key1":1, "key2":[2,3]}', "aLl", "$.key1", "$.key2")
9191
select json_contains_path('{ "a": true }', NULL, '$.a' );
9292
json_contains_path('{ "a": true }', NULL, '$.a' )
9393
NULL
94+
select json_contains_path('{ "a": true }', 'all', NULL );
95+
json_contains_path('{ "a": true }', 'all', NULL )
96+
NULL
9497
select json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1");
9598
json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1")
9699
"asd"

mysql-test/t/func_json.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ select json_contains_path('{"key1":1, "key2":[2,3]}', "one", "$.key1", "$.ma");
3636
select json_contains_path('{"key1":1, "key2":[2,3]}', "aLl", "$.key1", "$.ma");
3737
select json_contains_path('{"key1":1, "key2":[2,3]}', "aLl", "$.key1", "$.key2");
3838
select json_contains_path('{ "a": true }', NULL, '$.a' );
39+
select json_contains_path('{ "a": true }', 'all', NULL );
3940

4041
select json_extract('{"key1":"asd", "key2":[2,3]}', "$.key1");
4142
select json_extract('{"key1":"asd", "key2":[2,3]}', "$.keyX", "$.keyY");

sql/item_jsonfunc.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,9 @@ String *Item_func_json_extract::val_str(String *str)
450450
c_path->parsed= c_path->constant;
451451
}
452452

453+
if (args[n_arg]->null_value)
454+
goto error;
455+
453456
json_scan_start(&je, js->charset(),(const uchar *) js->ptr(),
454457
(const uchar *) js->ptr() + js->length());
455458

@@ -547,6 +550,9 @@ longlong Item_func_json_extract::val_int()
547550
c_path->parsed= c_path->constant;
548551
}
549552

553+
if (args[n_arg]->null_value)
554+
goto error;
555+
550556
json_scan_start(&je, js->charset(),(const uchar *) js->ptr(),
551557
(const uchar *) js->ptr() + js->length());
552558

@@ -661,6 +667,9 @@ longlong Item_func_json_contains::val_int()
661667
c_path->parsed= c_path->constant;
662668
}
663669

670+
if (args[n_arg]->null_value)
671+
goto error;
672+
664673
json_scan_start(&je, js->charset(),(const uchar *) js->ptr(),
665674
(const uchar *) js->ptr() + js->length());
666675

@@ -768,6 +777,9 @@ longlong Item_func_json_contains_path::val_int()
768777
c_path->parsed= c_path->constant;
769778
}
770779

780+
if (args[n_arg]->null_value)
781+
goto error;
782+
771783
json_scan_start(&je, js->charset(),(const uchar *) js->ptr(),
772784
(const uchar *) js->ptr() + js->length());
773785

@@ -1946,6 +1958,9 @@ String *Item_func_json_search::val_str(String *str)
19461958
}
19471959
}
19481960

1961+
if (args[n_arg]->null_value)
1962+
goto null_return;
1963+
19491964
json_scan_start(&je, js->charset(),(const uchar *) js->ptr(),
19501965
(const uchar *) js->ptr() + js->length());
19511966

0 commit comments

Comments
 (0)