From 3b3fc01425a89fd2c60890fb6019eb58dc121e03 Mon Sep 17 00:00:00 2001 From: Sergey Glukhov Date: Thu, 23 Apr 2009 12:43:42 +0500 Subject: [PATCH] Bug#44358 valgrind errors with decode() function The warning happens because string argument is not zero ended. The fix is to add new parameter 'length' to SQL_CRYPT() and use ptr() instead of c_ptr(). --- mysql-test/r/func_str.result | 14 ++++++++++++++ mysql-test/t/func_str.test | 12 ++++++++++++ sql/item_strfunc.cc | 4 ++-- sql/sql_crypt.cc | 4 ++-- sql/sql_crypt.h | 2 +- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 00c98ad136c..25cbf2470ed 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -2526,3 +2526,17 @@ h i 31.12.2008 AAAAAA, aaaaaa DROP TABLE t1; End of 5.0 tests +drop table if exists t1; +create table t1(f1 tinyint default null)engine=myisam; +insert into t1 values (-1),(null); +explain select 1 as a from t1,(select decode(f1,f1) as b from t1) a; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY ALL NULL NULL NULL NULL 2 Using join buffer +2 DERIVED t1 ALL NULL NULL NULL NULL 2 +explain select 1 as a from t1,(select encode(f1,f1) as b from t1) a; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY ALL NULL NULL NULL NULL 2 Using join buffer +2 DERIVED t1 ALL NULL NULL NULL NULL 2 +drop table t1; diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index b71dbe91467..ef406d2aeca 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -1283,3 +1283,15 @@ SELECT DATE_FORMAT(c, GET_FORMAT(DATE, 'eur')) h, CONCAT(UPPER(aa),', ', aa) i F DROP TABLE t1; --echo End of 5.0 tests + +# +# Bug#44358 valgrind errors with decode() function +# +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1(f1 tinyint default null)engine=myisam; +insert into t1 values (-1),(null); +explain select 1 as a from t1,(select decode(f1,f1) as b from t1) a; +explain select 1 as a from t1,(select encode(f1,f1) as b from t1) a; +drop table t1; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 5a8b1c6493c..5bb561fc1a9 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1742,7 +1742,7 @@ String *Item_func_encode::val_str(String *str) null_value=0; res=copy_if_not_alloced(str,res,res->length()); - SQL_CRYPT sql_crypt(password->ptr()); + SQL_CRYPT sql_crypt(password->ptr(), password->length()); sql_crypt.init(); sql_crypt.encode((char*) res->ptr(),res->length()); res->set_charset(&my_charset_bin); @@ -1771,7 +1771,7 @@ String *Item_func_decode::val_str(String *str) null_value=0; res=copy_if_not_alloced(str,res,res->length()); - SQL_CRYPT sql_crypt(password->ptr()); + SQL_CRYPT sql_crypt(password->ptr(), password->length()); sql_crypt.init(); sql_crypt.decode((char*) res->ptr(),res->length()); return res; diff --git a/sql/sql_crypt.cc b/sql/sql_crypt.cc index aa21d429d90..c4f93cc2a33 100644 --- a/sql/sql_crypt.cc +++ b/sql/sql_crypt.cc @@ -28,10 +28,10 @@ #include "mysql_priv.h" -SQL_CRYPT::SQL_CRYPT(const char *password) +SQL_CRYPT::SQL_CRYPT(const char *password, uint length) { ulong rand_nr[2]; - hash_password(rand_nr,password, (uint) strlen(password)); + hash_password(rand_nr,password, length); crypt_init(rand_nr); } diff --git a/sql/sql_crypt.h b/sql/sql_crypt.h index f3db9adde25..a5a6bee8a58 100644 --- a/sql/sql_crypt.h +++ b/sql/sql_crypt.h @@ -25,7 +25,7 @@ class SQL_CRYPT :public Sql_alloc uint shift; void crypt_init(ulong *seed); public: - SQL_CRYPT(const char *seed); + SQL_CRYPT(const char *seed, uint length); SQL_CRYPT(ulong *seed) { crypt_init(seed);