Skip to content

Commit

Permalink
MDEV-32867: ASAN errors in Item_func_json_contains_path::val_int upon…
Browse files Browse the repository at this point in the history
… PS execution

This bug was caused by a patch for the task MDEV-32733.
Incorrect memory root was used for allocation of memory
pointed by the data memebr Item_func_json_contains_path::p_found.
  • Loading branch information
dmitryshulga committed Nov 24, 2023
1 parent ead61d9 commit 85c1578
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions mysql-test/main/ps_mem_leaks.result
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,13 @@ DEALLOCATE PREPARE stmt;
DROP FUNCTION f1;
DROP VIEW v1;
DROP FUNCTION f2;
#
# MDEV-32867: ASAN errors in Item_func_json_contains_path::val_int upon PS execution
#
CREATE TABLE t1 (f BLOB) ENGINE=MyISAM;
PREPARE stmt FROM "SELECT * FROM t1 WHERE JSON_EXISTS(JSON_ARRAY('[true,1234567890]'), '$**.*') != JSON_CONTAINS_PATH(JSON_INSERT('{}', '$[1]', NULL), 'all', '$[1]')";
EXECUTE stmt;
f
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
# End of 10.4 tests
12 changes: 12 additions & 0 deletions mysql-test/main/ps_mem_leaks.test
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,16 @@ DROP FUNCTION f1;
DROP VIEW v1;
DROP FUNCTION f2;

--echo #
--echo # MDEV-32867: ASAN errors in Item_func_json_contains_path::val_int upon PS execution
--echo #
CREATE TABLE t1 (f BLOB) ENGINE=MyISAM;

PREPARE stmt FROM "SELECT * FROM t1 WHERE JSON_EXISTS(JSON_ARRAY('[true,1234567890]'), '$**.*') != JSON_CONTAINS_PATH(JSON_INSERT('{}', '$[1]', NULL), 'all', '$[1]')";
EXECUTE stmt;

# Clean up
DEALLOCATE PREPARE stmt;
DROP TABLE t1;

--echo # End of 10.4 tests
2 changes: 1 addition & 1 deletion sql/item_jsonfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ bool Item_func_json_contains_path::fix_fields(THD *thd, Item **ref)
if (!tmp_paths)
{
if (alloc_tmp_paths(thd, arg_count-2, &paths, &tmp_paths) ||
(p_found= (bool *) alloc_root(thd->mem_root,
(p_found= (bool *) alloc_root(thd->active_stmt_arena_to_use()->mem_root,
(arg_count-2)*sizeof(bool))) == NULL)
return true;
}
Expand Down

0 comments on commit 85c1578

Please sign in to comment.