Skip to content

Commit 59f3399

Browse files
author
Alexey Botchkov
committed
MDEV-25420 JSON_TABLE: ASAN heap-buffer-overflow in Protocol::net_store_data or consequent failures.
Create_tmp_table::add_field didn't consider BIT type field for null_counter.
1 parent 277aa53 commit 59f3399

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

mysql-test/suite/json/r/json_table.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,5 +832,14 @@ x TEXT PATH '$[9]')) AS jt GROUP BY x;
832832
x COUNT(*)
833833
NULL 1
834834
#
835+
# MDEV-25408 JSON_TABLE: AddressSanitizer CHECK failed in Binary_string::realloc_raw.
836+
#
837+
SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(
838+
a TEXT EXISTS PATH '$', b VARCHAR(40) PATH '$', c BIT(60) PATH '$', d VARCHAR(60) PATH '$', e BIT(62) PATH '$',
839+
f FOR ORDINALITY, g INT PATH '$', h VARCHAR(36) PATH '$', i DATE PATH '$', j CHAR(4) PATH '$'
840+
)) AS jt;
841+
a b c d e f g h i j
842+
1 NULL NULL NULL 1 NULL NULL NULL NULL
843+
#
835844
# End of 10.6 tests
836845
#

mysql-test/suite/json/t/json_table.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,5 +729,12 @@ SELECT x, COUNT(*) FROM JSON_TABLE( '{}', '$' COLUMNS(
729729
x TEXT PATH '$[9]')) AS jt GROUP BY x;
730730

731731
--echo #
732+
--echo # MDEV-25408 JSON_TABLE: AddressSanitizer CHECK failed in Binary_string::realloc_raw.
733+
--echo #
734+
SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(
735+
a TEXT EXISTS PATH '$', b VARCHAR(40) PATH '$', c BIT(60) PATH '$', d VARCHAR(60) PATH '$', e BIT(62) PATH '$',
736+
f FOR ORDINALITY, g INT PATH '$', h VARCHAR(36) PATH '$', i DATE PATH '$', j CHAR(4) PATH '$'
737+
)) AS jt;
738+
--echo #
732739
--echo # End of 10.6 tests
733740
--echo #

sql/sql_select.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18291,6 +18291,16 @@ Create_tmp_table::Create_tmp_table(ORDER *group, bool distinct,
1829118291
}
1829218292

1829318293

18294+
static void add_null_bits_for_field(const Field *f, uint *null_counter)
18295+
{
18296+
if (!f->flags & NOT_NULL_FLAG)
18297+
(*null_counter)++;
18298+
18299+
if (f->type() != MYSQL_TYPE_BIT)
18300+
(*null_counter)+= f->field_length & 7;
18301+
}
18302+
18303+
1829418304
void Create_tmp_table::add_field(TABLE *table, Field *field, uint fieldnr,
1829518305
bool force_not_null_cols)
1829618306
{
@@ -18303,8 +18313,7 @@ void Create_tmp_table::add_field(TABLE *table, Field *field, uint fieldnr,
1830318313
field->null_ptr= NULL;
1830418314
}
1830518315

18306-
if (!(field->flags & NOT_NULL_FLAG))
18307-
m_null_count[current_counter]++;
18316+
add_null_bits_for_field(field, m_null_count + current_counter);
1830818317

1830918318
table->s->reclength+= field->pack_length();
1831018319

@@ -18885,7 +18894,6 @@ bool Create_tmp_table::finalize(THD *thd,
1888518894
recinfo->null_pos= (null_pack_base[current_counter] +
1888618895
null_counter[current_counter]/8);
1888718896
field->move_field(pos, null_flags + recinfo->null_pos, recinfo->null_bit);
18888-
null_counter[current_counter]++;
1888918897
}
1889018898
else
1889118899
field->move_field(pos,(uchar*) 0,0);
@@ -18896,8 +18904,9 @@ bool Create_tmp_table::finalize(THD *thd,
1889618904
null_pack_base[current_counter] +
1889718905
null_counter[current_counter]/8,
1889818906
null_counter[current_counter] & 7);
18899-
null_counter[current_counter]+= (field->field_length & 7);
1890018907
}
18908+
18909+
add_null_bits_for_field(field, null_counter + current_counter);
1890118910
field->reset();
1890218911

1890318912
/*

0 commit comments

Comments
 (0)