Skip to content
/ server Public

Commit 291cc20

Browse files
MDEV-33640: Server crashes at my_hash_free
Analysis: While parsing the json schema, we dont initialize the hash that stores properties, but we try to free hash while cleanup. This happend because the variable that checks whether hash is initialized has garbage value. So the check becomes true and we end up deleting the uninitialized hash. Fix: Initialize the is_hash_inited to false.
1 parent 4deadb9 commit 291cc20

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

mysql-test/main/func_json.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5379,4 +5379,9 @@ result
53795379
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
53805380
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
53815381
[["2", "6"], ["3", "8"], ["4", "5"], ["1", "7"]]
5382+
#
5383+
# MDEV-33640: Server crashes at my_hash_free
5384+
#
5385+
SELECT JSON_SCHEMA_VALID('{"properties": "a_string": {"pattern": "^[5-9]$"}}}', '{"a_string": "8"}');
5386+
ERROR HY000: Invalid value for keyword properties
53825387
# End of 11.4 Test

mysql-test/main/func_json.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4275,4 +4275,12 @@ SELECT ( WITH x AS ( WITH x ( x ) AS ( SELECT ( 1.000000 ) ) SELECT x FROM x ) S
42754275

42764276
select json_array_intersect('[["1", "7"], ["2", "6"], ["4", "5"], ["3", "8"]]', '[["2","6"],["3","8"],["4","5"],["1","7"]]') as result from (values (1),(2),(3),(4),(5)) x;
42774277

4278+
4279+
--echo #
4280+
--echo # MDEV-33640: Server crashes at my_hash_free
4281+
--echo #
4282+
4283+
--error ER_JSON_INVALID_VALUE_FOR_KEYWORD
4284+
SELECT JSON_SCHEMA_VALID('{"properties": "a_string": {"pattern": "^[5-9]$"}}}', '{"a_string": "8"}');
4285+
42784286
--echo # End of 11.4 Test

sql/json_schema.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ class Json_schema_properties : public Json_schema_keyword
475475
Json_schema_properties()
476476
{
477477
priority= 1;
478+
is_hash_inited= false;
478479
}
479480
bool validate(const json_engine_t *je, const uchar *k_start= NULL,
480481
const uchar *k_end= NULL) override;
@@ -503,6 +504,10 @@ class Json_schema_dependent_schemas : public Json_schema_keyword
503504
if (is_hash_inited)
504505
my_hash_free(&properties);
505506
}
507+
Json_schema_dependent_schemas()
508+
{
509+
is_hash_inited= false;
510+
}
506511
bool validate(const json_engine_t *je, const uchar *k_start= NULL,
507512
const uchar *k_end= NULL) override;
508513
bool handle_keyword(THD *thd, json_engine_t *je,

0 commit comments

Comments
 (0)