Skip to content

Commit 1232fca

Browse files
author
Varun Deep Saini
committed
MDEV-35548: Fix out-of-bounds array access in json_get_path_start
json_get_path_start() set p->last_step to p->steps - 1, creating a pointer before the beginning of the steps[] array. This is undefined behavior flagged by UBSAN as "index -1 out of bounds for type json_path_step_t[32]". Use NULL as the sentinel value instead, and check for NULL in json_get_path_next() rather than comparing against p->steps. Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
1 parent e520abd commit 1232fca

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

mysql-test/main/func_json.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,14 @@ null<=>json_extract('1',json_object(null,'{ }',null,null),'{}')
17731773
1
17741774
Warnings:
17751775
Warning 4042 Syntax error in JSON path in argument 2 to function 'json_extract' at position 1
1776+
SELECT JSON_EXTRACT('{a:true}','$.a')=TRUE;
1777+
JSON_EXTRACT('{a:true}','$.a')=TRUE
1778+
NULL
1779+
Warnings:
1780+
Warning 4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 2
1781+
SELECT JSON_EXTRACT('0E+0','$');
1782+
JSON_EXTRACT('0E+0','$')
1783+
0E+0
17761784
#
17771785
# End of 10.6 tests
17781786
#

mysql-test/main/func_json.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,10 @@ FROM JSON_TABLE (@data, '$[*]' COLUMNS (data text PATH '$.Data')) AS t;
12391239
select null<=>json_extract('1',json_object(null,'{ }',null,null),'{}');
12401240

12411241

1242+
1243+
SELECT JSON_EXTRACT('{a:true}','$.a')=TRUE;
1244+
SELECT JSON_EXTRACT('0E+0','$');
1245+
12421246
--echo #
12431247
--echo # End of 10.6 tests
12441248
--echo #

strings/json_lib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,14 +1701,14 @@ int json_get_path_start(json_engine_t *je, CHARSET_INFO *i_cs,
17011701
json_path_t *p)
17021702
{
17031703
json_scan_start(je, i_cs, str, end);
1704-
p->last_step= p->steps - 1;
1704+
p->last_step= NULL;
17051705
return 0;
17061706
}
17071707

17081708

17091709
int json_get_path_next(json_engine_t *je, json_path_t *p)
17101710
{
1711-
if (p->last_step < p->steps)
1711+
if (p->last_step == NULL)
17121712
{
17131713
if (json_read_value(je))
17141714
return 1;

0 commit comments

Comments
 (0)