Skip to content

Commit

Permalink
MDEV-33392 Server crashes when using RANDOM_BYTES function and GROUP …
Browse files Browse the repository at this point in the history
…BY clause on a column with a negative value

Item_func_random_bytes did not set its NULL-ability flag.
  • Loading branch information
abarkov committed Feb 7, 2024
1 parent 7f3839a commit c4c1677
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
34 changes: 34 additions & 0 deletions mysql-test/main/func_str.result
Original file line number Diff line number Diff line change
Expand Up @@ -5460,3 +5460,37 @@ Warning 1292 Truncated incorrect BINARY(2) value: '...random bytes...'
#
# End of 10.10 tests
#
#
# Start of 10.11 tests
#
#
# MDEV-33392 Server crashes when using RANDOM_BYTES function and GROUP BY clause on a column with a negative value
#
SET sql_mode='';
CREATE TABLE t1 (a VARCHAR(255)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (9494),(9495),(9496),(9497),(9498),(9499),(9500),(9501),(9502),(9503);
SELECT RANDOM_BYTES (-1) f1,a f2 FROM t1 GROUP BY f1,f2;
f1 f2
NULL 9494
NULL 9495
NULL 9496
NULL 9497
NULL 9498
NULL 9499
NULL 9500
NULL 9501
NULL 9502
NULL 9503
CREATE TABLE t2 AS SELECT RANDOM_BYTES (-1) f1,a f2 FROM t1 GROUP BY f1,f2;
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
`f1` binary(0) DEFAULT NULL,
`f2` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DROP TABLE t2;
DROP TABLE t1;
SET sql_mode=DEFAULT;
#
# End of 10.11 tests
#
22 changes: 22 additions & 0 deletions mysql-test/main/func_str.test
Original file line number Diff line number Diff line change
Expand Up @@ -2435,3 +2435,25 @@ select "a" in ("abc", (convert(random_bytes(8) ,binary(2))));
--echo #
--echo # End of 10.10 tests
--echo #

--echo #
--echo # Start of 10.11 tests
--echo #

--echo #
--echo # MDEV-33392 Server crashes when using RANDOM_BYTES function and GROUP BY clause on a column with a negative value
--echo #

SET sql_mode='';
CREATE TABLE t1 (a VARCHAR(255)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (9494),(9495),(9496),(9497),(9498),(9499),(9500),(9501),(9502),(9503);
SELECT RANDOM_BYTES (-1) f1,a f2 FROM t1 GROUP BY f1,f2;
CREATE TABLE t2 AS SELECT RANDOM_BYTES (-1) f1,a f2 FROM t1 GROUP BY f1,f2;
SHOW CREATE TABLE t2;
DROP TABLE t2;
DROP TABLE t1;
SET sql_mode=DEFAULT;

--echo #
--echo # End of 10.11 tests
--echo #
1 change: 1 addition & 0 deletions sql/item_strfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1509,6 +1509,7 @@ String *Item_func_sformat::val_str(String *res)

bool Item_func_random_bytes::fix_length_and_dec(THD *thd)
{
set_maybe_null();
used_tables_cache|= RAND_TABLE_BIT;
if (args[0]->can_eval_in_optimize())
{
Expand Down

0 comments on commit c4c1677

Please sign in to comment.