diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index 19b48efe6b4..ad56ddc2e94 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -797,6 +797,9 @@ set @@query_prealloc_size = @test; select @@query_prealloc_size = @test; @@query_prealloc_size = @test 1 +set global sql_mode=repeat('a',80); +ERROR 42000: Variable 'sql_mode' can't be set to the value of 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' +End of 4.1 tests create table t1 (a int); select a into @x from t1; Warnings: diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 81db143b518..495cfe4445a 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -574,7 +574,14 @@ set @test = @@query_prealloc_size; set @@query_prealloc_size = @test; select @@query_prealloc_size = @test; -# End of 4.1 tests +# +# Bug#31588 buffer overrun when setting variables +# +# Buffer-size Off By One. Should throw valgrind-warning without fix #31588. +--error 1231 +set global sql_mode=repeat('a',80); + +--echo End of 4.1 tests # # Bug#6282 Packet error with SELECT INTO diff --git a/sql/set_var.cc b/sql/set_var.cc index 697de9cda97..65386e58202 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1405,7 +1405,7 @@ bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names) ¬_used)); if (error_len) { - strmake(buff, error, min(sizeof(buff), error_len)); + strmake(buff, error, min(sizeof(buff) - 1, error_len)); goto err; } }