Skip to content

Commit 1ae06b9

Browse files
committed
MDEV-37947 Item_func_hex doesn't check for max_allowed_packet
1 parent fa9ab77 commit 1ae06b9

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

mysql-test/main/func_str.result

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
drop table if exists t1,t2;
21
set @save_max_allowed_packet=@@global.max_allowed_packet;
32
set global max_allowed_packet=1048576;
43
connect conn1,localhost,root,,;
@@ -5415,5 +5414,11 @@ t1 CREATE TABLE `t1` (
54155414
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
54165415
DROP TABLE t1;
54175416
#
5418-
# End of 10.6 tests
5417+
# MDEV-37947 Item_func_hex doesn't check for max_allowed_packet
54195418
#
5419+
select hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex('\\'))))))))))))))))))))))))))))))))))))))))))))) as x;
5420+
x
5421+
NULL
5422+
Warnings:
5423+
Warning 1301 Result of hex() was larger than max_allowed_packet (16777216) - truncated
5424+
# End of 10.6 tests

mysql-test/main/func_str.test

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# -----------
33
# Testing string functions
44

5-
--disable_warnings
6-
drop table if exists t1,t2;
7-
--enable_warnings
8-
95
set @save_max_allowed_packet=@@global.max_allowed_packet;
106
set global max_allowed_packet=1048576;
117
connect (conn1,localhost,root,,);
@@ -2455,5 +2451,8 @@ SHOW CREATE TABLE t1;
24552451
DROP TABLE t1;
24562452

24572453
--echo #
2458-
--echo # End of 10.6 tests
2454+
--echo # MDEV-37947 Item_func_hex doesn't check for max_allowed_packet
24592455
--echo #
2456+
select hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex(hex('\\'))))))))))))))))))))))))))))))))))))))))))))) as x;
2457+
2458+
--echo # End of 10.6 tests

sql/item_strfunc.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3828,9 +3828,21 @@ String *Item_func_hex::val_str_ascii_from_val_str(String *str)
38283828
{
38293829
DBUG_ASSERT(&tmp_value != str);
38303830
String *res= args[0]->val_str(&tmp_value);
3831-
DBUG_ASSERT(res != str);
3831+
THD *thd= current_thd;
3832+
38323833
if ((null_value= (res == NULL)))
38333834
return NULL;
3835+
3836+
if (res->length()*2 > thd->variables.max_allowed_packet)
3837+
{
3838+
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
3839+
ER_WARN_ALLOWED_PACKET_OVERFLOWED,
3840+
ER_THD(thd, ER_WARN_ALLOWED_PACKET_OVERFLOWED),
3841+
func_name(), thd->variables.max_allowed_packet);
3842+
null_value= true;
3843+
return NULL;
3844+
}
3845+
38343846
return str->set_hex(res->ptr(), res->length()) ? make_empty_result(str) : str;
38353847
}
38363848

0 commit comments

Comments
 (0)