1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

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

We should be ready for an empty key.
This commit is contained in:
Alexey Botchkov
2017-02-09 17:38:53 +04:00
parent 66c6188a4b
commit 0e6968c244
3 changed files with 16 additions and 5 deletions

View File

@ -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');

View File

@ -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 @@ skip_search:
{
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) ||

View File

@ -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. */