Commit 0e6968c2 authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-11857 json_search() shows "Out of memory" with empty key.

        We should be ready for an empty key.
parent 66c6188a
......@@ -220,3 +220,8 @@ SELECT json_replace('1', '$[0][0]', 100);
SELECT json_replace('[]', '$[0][0]', 100);
SELECT json_set('[]', '$[0][0]', 100);
SELECT json_set('[]', '$[0][0][0]', 100);
#
# MDEV-11857 json_search() shows "Out of memory" with empty key.
#
SELECT JSON_search( '{"": "a"}', "one", 'a');
......@@ -147,8 +147,10 @@ static int json_nice(json_engine_t *je, String *nice_js,
const uchar *key_start= je->s.c_str;
const uchar *key_end;
while (json_read_keyname_chr(je) == 0)
do
{
key_end= je->s.c_str;
} while (json_read_keyname_chr(je) == 0);
if (je->s.error)
goto error;
......@@ -892,8 +894,10 @@ static int check_contains(json_engine_t *js, json_engine_t *value)
DBUG_ASSERT(value->state == JST_KEY);
k_start= value->s.c_str;
while (json_read_keyname_chr(value) == 0)
do
{
k_end= value->s.c_str;
} while (json_read_keyname_chr(value) == 0);
if (value->s.error || json_read_value(value))
return FALSE;
......@@ -2527,10 +2531,10 @@ String *Item_func_json_keys::val_str(String *str)
{
case JST_KEY:
key_start= je.s.c_str;
while (json_read_keyname_chr(&je) == 0)
do
{
key_end= je.s.c_str;
}
} while (json_read_keyname_chr(&je) == 0);
if (je.s.error ||
(n_keys > 0 && str->append(", ", 2)) ||
str->append("\"", 1) ||
......
......@@ -1701,8 +1701,10 @@ int json_get_path_next(json_engine_t *je, json_path_t *p)
{
case JST_KEY:
p->last_step->key= je->s.c_str;
while (json_read_keyname_chr(je) == 0)
do
{
p->last_step->key_end= je->s.c_str;
} while (json_read_keyname_chr(je) == 0);
if (je->s.error)
return 1;
/* Now we have je.state == JST_VALUE, so let's handle it. */
......
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