Skip to content

Commit 12c1071

Browse files
grooverdanspetrunia
authored andcommitted
MDEV-36765: followup 3: json_unquote/compare_json_str_basic handle errors from json_unescape
Using report_json_error was incorrect as errors in the je have already been handled earlier in the json function. The errors related to json_unescape are handled with consistently with other functions.
1 parent 2b24ed8 commit 12c1071

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

sql/item_jsonfunc.cc

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ String *Item_func_json_unquote::read_json(json_engine_t *je)
907907
String *Item_func_json_unquote::val_str(String *str)
908908
{
909909
json_engine_t je;
910-
int c_len;
910+
int c_len= JSON_ERROR_OUT_OF_SPACE;
911911
String *js;
912912

913913
if (!(js= read_json(&je)))
@@ -930,7 +930,15 @@ String *Item_func_json_unquote::val_str(String *str)
930930
return str;
931931

932932
error:
933-
report_json_error(js, &je, 0);
933+
if (current_thd)
934+
{
935+
if (c_len == JSON_ERROR_OUT_OF_SPACE)
936+
my_error(ER_OUTOFMEMORY, MYF(0), je.value_len);
937+
else if (c_len == JSON_ERROR_ILLEGAL_SYMBOL)
938+
push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
939+
ER_JSON_BAD_CHR, ER_THD(current_thd, ER_JSON_BAD_CHR),
940+
0, "unquote", 0);
941+
}
934942
return js;
935943
}
936944

@@ -4195,9 +4203,14 @@ int Arg_comparator::compare_json_str_basic(Item *j, Item *s)
41954203
(uchar *) (value2.ptr() + je.value_len))) < 0)
41964204
{
41974205
if (current_thd)
4198-
push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
4199-
ER_JSON_BAD_CHR, ER_THD(current_thd, ER_JSON_BAD_CHR),
4200-
0, "comparison", (int)((const char *) je.s.c_str - js->ptr()));
4206+
{
4207+
if (c_len == JSON_ERROR_OUT_OF_SPACE)
4208+
my_error(ER_OUTOFMEMORY, MYF(0), je.value_len);
4209+
else if (c_len == JSON_ERROR_ILLEGAL_SYMBOL)
4210+
push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
4211+
ER_JSON_BAD_CHR, ER_THD(current_thd, ER_JSON_BAD_CHR),
4212+
0, "comparison", (int)((const char *) je.s.c_str - js->ptr()));
4213+
}
42014214
goto error;
42024215
}
42034216

@@ -4254,10 +4267,15 @@ int Arg_comparator::compare_e_json_str_basic(Item *j, Item *s)
42544267
(uchar *) (value1.ptr() + value_len))) < 0)
42554268
{
42564269
if (current_thd)
4257-
push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
4258-
ER_JSON_BAD_CHR, ER_THD(current_thd, ER_JSON_BAD_CHR),
4259-
0, "equality comparison", 0);
4260-
return 1;
4270+
{
4271+
if (c_len == JSON_ERROR_OUT_OF_SPACE)
4272+
my_error(ER_OUTOFMEMORY, MYF(0), value_len);
4273+
else if (c_len == JSON_ERROR_ILLEGAL_SYMBOL)
4274+
push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
4275+
ER_JSON_BAD_CHR, ER_THD(current_thd, ER_JSON_BAD_CHR),
4276+
0, "equality comparison", 0);
4277+
}
4278+
return 1;
42614279
}
42624280
value1.length(c_len);
42634281
res1= &value1;

0 commit comments

Comments
 (0)