Commit fa2e1c39 authored by Rucha Deodhar's avatar Rucha Deodhar

MDEV-33015: Server crashes upon JSON_SCHEMA_VALID reading NULL from a user

variable

Analysis:
Since the item is NULL, it's json value is NULL but we proceed to parse
it anyway.
Fix:
If json value is NULL, return NULL.
parent 187cbfca
......@@ -4737,4 +4737,11 @@ NULL
#
PREPARE s FROM 'SELECT JSON_SCHEMA_VALID (?,''{}'') FROM DUAL';
ERROR HY000: Variable schema is not supported.
#
# MDEV-33015: Server crashes upon JSON_SCHEMA_VALID reading NULL from a user variable
#
SET @a= NULL;
SELECT JSON_SCHEMA_VALID(@a,'{}');
JSON_SCHEMA_VALID(@a,'{}')
NULL
# End of 11.1 test
......@@ -3708,4 +3708,12 @@ SELECT JSON_SCHEMA_VALID(NULL, NULL);
--error ER_JSON_NO_VARIABLE_SCHEMA
PREPARE s FROM 'SELECT JSON_SCHEMA_VALID (?,''{}'') FROM DUAL';
--echo #
--echo # MDEV-33015: Server crashes upon JSON_SCHEMA_VALID reading NULL from a user variable
--echo #
SET @a= NULL;
SELECT JSON_SCHEMA_VALID(@a,'{}');
--echo # End of 11.1 test
......@@ -4809,17 +4809,21 @@ bool Item_func_json_schema_valid::fix_length_and_dec(THD *thd)
String *js= NULL;
if (!is_schema_constant || (null_value= args[0]->null_value))
if (!is_schema_constant)
{
if (!is_schema_constant)
{
my_error(ER_JSON_NO_VARIABLE_SCHEMA, MYF(0));
}
my_error(ER_JSON_NO_VARIABLE_SCHEMA, MYF(0));
null_value= 1;
return 0;
}
null_value= args[0]->null_value;
js= args[0]->val_json(&tmp_js);
if (!js)
{
null_value= 1;
return 0;
}
json_scan_start(&je, js->charset(), (const uchar *) js->ptr(),
(const uchar *) js->ptr() + js->length());
if (!create_object_and_handle_keyword(thd, &je, &keyword_list,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment