Skip to content

Commit 5d3e14d

Browse files
MDEV-31599: Assertion `0' failed in Item_param::can_return_value
from Item::val_json, UBSAN: member access within null pointer of type 'struct String' in sql/item_jsonfunc.cc Analysis: The first argument of json_schema_valid() needs to be a constant. Fix: Parse the schema if the item is constant otherwise set it to return null.
1 parent 855356c commit 5d3e14d

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

mysql-test/main/func_json.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4762,4 +4762,11 @@ NULL
47624762
SELECT JSON_SCHEMA_VALID(NULL, NULL);
47634763
JSON_SCHEMA_VALID(NULL, NULL)
47644764
NULL
4765+
#
4766+
# MDEV-31599: Assertion `0' failed in Item_param::can_return_value from Item::val_json,
4767+
# UBSAN: member access within null pointer of type 'struct String' in
4768+
# sql/item_jsonfunc.cc
4769+
#
4770+
PREPARE s FROM 'SELECT JSON_SCHEMA_VALID (?,''{}'') FROM DUAL';
4771+
ERROR HY000: Variable schema is not supported.
47654772
# End of 11.1 test

mysql-test/main/func_json.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3647,4 +3647,13 @@ SELECT JSON_SCHEMA_VALID('{}', NULL);
36473647
SELECT JSON_SCHEMA_VALID(NULL, '{}');
36483648
SELECT JSON_SCHEMA_VALID(NULL, NULL);
36493649

3650+
--echo #
3651+
--echo # MDEV-31599: Assertion `0' failed in Item_param::can_return_value from Item::val_json,
3652+
--echo # UBSAN: member access within null pointer of type 'struct String' in
3653+
--echo # sql/item_jsonfunc.cc
3654+
--echo #
3655+
3656+
--error ER_JSON_NO_VARIABLE_SCHEMA
3657+
PREPARE s FROM 'SELECT JSON_SCHEMA_VALID (?,''{}'') FROM DUAL';
3658+
36503659
--echo # End of 11.1 test

sql/item_jsonfunc.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4798,15 +4798,21 @@ If any of them fails, return false, else return true.
47984798
bool Item_func_json_schema_valid::fix_length_and_dec(THD *thd)
47994799
{
48004800
json_engine_t je;
4801-
bool res= 0;
4801+
bool res= 0, is_schema_constant= args[0]->const_item();
48024802

4803-
String *js= args[0]->val_json(&tmp_js);
4803+
String *js= NULL;
48044804

4805-
if ((null_value= args[0]->null_value))
4805+
if (!is_schema_constant || (null_value= args[0]->null_value))
48064806
{
4807+
if (!is_schema_constant)
4808+
{
4809+
my_error(ER_JSON_NO_VARIABLE_SCHEMA, MYF(0));
4810+
}
48074811
null_value= 1;
48084812
return 0;
48094813
}
4814+
js= args[0]->val_json(&tmp_js);
4815+
48104816
json_scan_start(&je, js->charset(), (const uchar *) js->ptr(),
48114817
(const uchar *) js->ptr() + js->length());
48124818
if (!create_object_and_handle_keyword(thd, &je, &keyword_list,

sql/share/errmsg-utf8.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11972,3 +11972,5 @@ ER_JSON_INVALID_VALUE_FOR_KEYWORD
1197211972
ER_JSON_SCHEMA_KEYWORD_UNSUPPORTED
1197311973
eng "%s keyword is not supported"
1197411974
sw "%s neno kuu halitumiki"
11975+
ER_JSON_NO_VARIABLE_SCHEMA
11976+
eng "Variable schema is not supported."

0 commit comments

Comments
 (0)