1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-29154 Excessive warnings upon a call to RANDOM_BYTES

Bring the 5 warnings of select random_bytes(cast('x' as unsigned)+1);
back to two. 1 for Item_func_random_bytes::fix_length_and_dec and
one from Item_func_random_bytes::val_str.

The warnings are from args[0]->val_int().
This commit is contained in:
Daniel Black
2022-07-23 15:58:13 +10:00
committed by Sergei Golubchik
parent 7f06f68108
commit d7e3265dd3
4 changed files with 25 additions and 3 deletions

View File

@ -5327,5 +5327,20 @@ 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)' ERROR 22003: length value is out of range in 'random_bytes(-10)'
DROP TABLE t; DROP TABLE t;
# #
# MDEV-29154: Excessive warnings upon a call to RANDOM_BYTES
#
select length(random_bytes(cast('x' as unsigned)+1));
length(random_bytes(cast('x' as unsigned)+1))
1
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'x'
Warning 1292 Truncated incorrect INTEGER value: 'x'
select repeat('.', cast('x' as unsigned)+1);
repeat('.', cast('x' as unsigned)+1)
.
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'x'
Warning 1292 Truncated incorrect INTEGER value: 'x'
#
# End of 10.10 tests # End of 10.10 tests
# #

View File

@ -2259,6 +2259,13 @@ SELECT RANDOM_BYTES(-10) f1, IFNULL(a,1) f2 FROM t GROUP BY f1, f2;
# Cleanup # Cleanup
DROP TABLE t; DROP TABLE t;
--echo #
--echo # MDEV-29154: Excessive warnings upon a call to RANDOM_BYTES
--echo #
select length(random_bytes(cast('x' as unsigned)+1));
select repeat('.', cast('x' as unsigned)+1);
--echo # --echo #
--echo # End of 10.10 tests --echo # End of 10.10 tests
--echo # --echo #

View File

@ -1478,14 +1478,13 @@ String *Item_func_sformat::val_str(String *res)
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/err.h> #include <openssl/err.h>
static const int MAX_RANDOM_BYTES= 1024;
bool Item_func_random_bytes::fix_length_and_dec(THD *thd) bool Item_func_random_bytes::fix_length_and_dec(THD *thd)
{ {
used_tables_cache|= RAND_TABLE_BIT; used_tables_cache|= RAND_TABLE_BIT;
if (args[0]->can_eval_in_optimize()) if (args[0]->can_eval_in_optimize())
{ {
max_length= MY_MAX(0, MY_MIN((int32) args[0]->val_int(), MAX_RANDOM_BYTES)); int32 v= (int32) args[0]->val_int();
max_length= MY_MAX(0, MY_MIN(v, MAX_RANDOM_BYTES));
return false; return false;
} }
max_length= MAX_RANDOM_BYTES; max_length= MAX_RANDOM_BYTES;

View File

@ -406,6 +406,7 @@ public:
{ {
return get_item_copy<Item_func_random_bytes>(thd, this); return get_item_copy<Item_func_random_bytes>(thd, this);
} }
static const int MAX_RANDOM_BYTES= 1024;
}; };