diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result index 88429defc40..2ac38f4f4da 100644 --- a/mysql-test/main/func_str.result +++ b/mysql-test/main/func_str.result @@ -5279,9 +5279,14 @@ drop table t1; select count(*) from seq_17_to_1024 where random_bytes(seq) <=> random_bytes(seq); count(*) 0 -select (count(*) = 1024) from seq_1_to_1024 where length(random_bytes(seq)) = seq; -(count(*) = 1024) -1 +select count(*) from seq_1_to_1024 where length(random_bytes(seq)) = seq; +count(*) +1024 +select random_bytes(`0`),`1` from (values (0,1),(null,2),(0,3)) t1; +random_bytes(`0`) 1 + 1 +NULL 2 + 3 # # Test NULL output for NULL input # @@ -5289,42 +5294,68 @@ SELECT random_bytes(NULL); random_bytes(NULL) NULL # -# Test For values outside range from 1 to 1024, an error occurs +# Test For values outside range from 1 to 1024 return NULL # SELECT random_bytes(0); -ERROR 22003: length value is out of range in 'random_bytes(0)' +random_bytes(0) + SELECT random_bytes(-1); -ERROR 22003: length value is out of range in 'random_bytes(-1)' +random_bytes(-1) +NULL SELECT random_bytes(-100); -ERROR 22003: length value is out of range in 'random_bytes(-100)' +random_bytes(-100) +NULL SELECT random_bytes(-26); -ERROR 22003: length value is out of range in 'random_bytes(-26)' +random_bytes(-26) +NULL SELECT random_bytes(-132); -ERROR 22003: length value is out of range in 'random_bytes(-132)' +random_bytes(-132) +NULL SELECT random_bytes(1025); -ERROR 22003: length value is out of range in 'random_bytes(1025)' +random_bytes(1025) +NULL SELECT random_bytes(11111); -ERROR 22003: length value is out of range in 'random_bytes(11111)' +random_bytes(11111) +NULL SELECT random_bytes(2056); -ERROR 22003: length value is out of range in 'random_bytes(2056)' +random_bytes(2056) +NULL # -# Test For invalid argument, an error occurs +# Test For invalid argument return NULL # SELECT random_bytes('s'); -ERROR 22003: length value is out of range in 'random_bytes('s')' +random_bytes('s') + +Warnings: +Warning 1292 Truncated incorrect INTEGER value: 's' +Warning 1292 Truncated incorrect INTEGER value: 's' SELECT random_bytes('r'); -ERROR 22003: length value is out of range in 'random_bytes('r')' +random_bytes('r') + +Warnings: +Warning 1292 Truncated incorrect INTEGER value: 'r' +Warning 1292 Truncated incorrect INTEGER value: 'r' SELECT random_bytes('res'); -ERROR 22003: length value is out of range in 'random_bytes('res')' +random_bytes('res') + +Warnings: +Warning 1292 Truncated incorrect INTEGER value: 'res' +Warning 1292 Truncated incorrect INTEGER value: 'res' SELECT random_bytes('test'); -ERROR 22003: length value is out of range in 'random_bytes('test')' +random_bytes('test') + +Warnings: +Warning 1292 Truncated incorrect INTEGER value: 'test' +Warning 1292 Truncated incorrect INTEGER value: 'test' # # MDEV-29108: RANDOM_BYTES - assertion in Create_tmp_table::finalize # CREATE TABLE t (a INT); INSERT INTO t VALUES (1),(2); SELECT RANDOM_BYTES(-10) f1, IFNULL(a,1) f2 FROM t GROUP BY f1, f2; -ERROR 22003: length value is out of range in 'random_bytes(-10)' +f1 f2 +NULL 1 +NULL 2 DROP TABLE t; # # MDEV-29154: Excessive warnings upon a call to RANDOM_BYTES diff --git a/mysql-test/main/func_str.test b/mysql-test/main/func_str.test index c8546e474d1..e27e042d3dc 100644 --- a/mysql-test/main/func_str.test +++ b/mysql-test/main/func_str.test @@ -2206,7 +2206,9 @@ drop table t1; --echo # The sequence starts at 17 so that the probability of test failure is small enough (about 2^(-136)) select count(*) from seq_17_to_1024 where random_bytes(seq) <=> random_bytes(seq); -select (count(*) = 1024) from seq_1_to_1024 where length(random_bytes(seq)) = seq; +select count(*) from seq_1_to_1024 where length(random_bytes(seq)) = seq; + +select random_bytes(`0`),`1` from (values (0,1),(null,2),(0,3)) t1; --echo # --echo # Test NULL output for NULL input @@ -2215,36 +2217,24 @@ select (count(*) = 1024) from seq_1_to_1024 where length(random_bytes(seq)) = se SELECT random_bytes(NULL); --echo # ---echo # Test For values outside range from 1 to 1024, an error occurs +--echo # Test For values outside range from 1 to 1024 return NULL --echo # ---error 1690 SELECT random_bytes(0); ---error 1690 SELECT random_bytes(-1); ---error 1690 SELECT random_bytes(-100); ---error 1690 SELECT random_bytes(-26); ---error 1690 SELECT random_bytes(-132); ---error 1690 SELECT random_bytes(1025); ---error 1690 SELECT random_bytes(11111); ---error 1690 SELECT random_bytes(2056); --echo # ---echo # Test For invalid argument, an error occurs +--echo # Test For invalid argument return NULL --echo # ---error 1690 SELECT random_bytes('s'); ---error 1690 SELECT random_bytes('r'); ---error 1690 SELECT random_bytes('res'); ---error 1690 SELECT random_bytes('test'); --echo # @@ -2253,7 +2243,6 @@ SELECT random_bytes('test'); CREATE TABLE t (a INT); INSERT INTO t VALUES (1),(2); ---error 1690 SELECT RANDOM_BYTES(-10) f1, IFNULL(a,1) f2 FROM t GROUP BY f1, f2; # Cleanup diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 1a78efce0dc..2eebe78929b 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1507,15 +1507,11 @@ String *Item_func_random_bytes::val_str(String *str) goto err; null_value= 0; - if (count < 1 || count > MAX_RANDOM_BYTES) - { - char buf[256]; - String msg(buf, sizeof(buf), system_charset_info); - msg.length(0); - print(&msg, QT_NO_DATA_EXPANSION); - my_error(ER_DATA_OUT_OF_RANGE, MYF(0), "length", msg.c_ptr_safe()); + if (count < 0 || count > MAX_RANDOM_BYTES) + goto err; + + if (count == 0) return make_empty_result(str); - } if (str->alloc((uint) count)) goto err; @@ -1530,7 +1526,7 @@ String *Item_func_random_bytes::val_str(String *str) ERR_error_string_n(ssl_err, buf, sizeof(buf)); sql_print_warning("SSL error: %s", buf); } - return make_empty_result(str); + goto err; } return str;