Commit d7e3265d authored by Daniel Black's avatar Daniel Black Committed by Sergei Golubchik

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().
parent 7f06f681
......@@ -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)'
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
#
......@@ -2259,6 +2259,13 @@ SELECT RANDOM_BYTES(-10) f1, IFNULL(a,1) f2 FROM t GROUP BY f1, f2;
# Cleanup
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 # End of 10.10 tests
--echo #
......@@ -1478,14 +1478,13 @@ String *Item_func_sformat::val_str(String *res)
#include <openssl/rand.h>
#include <openssl/err.h>
static const int MAX_RANDOM_BYTES= 1024;
bool Item_func_random_bytes::fix_length_and_dec(THD *thd)
{
used_tables_cache|= RAND_TABLE_BIT;
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;
}
max_length= MAX_RANDOM_BYTES;
......
......@@ -406,6 +406,7 @@ class Item_func_random_bytes : public Item_str_func
{
return get_item_copy<Item_func_random_bytes>(thd, this);
}
static const int MAX_RANDOM_BYTES= 1024;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment