diff options
author | Sergey Glukhov <Sergey.Glukhov@sun.com> | 2009-04-23 12:43:42 +0500 |
---|---|---|
committer | Sergey Glukhov <Sergey.Glukhov@sun.com> | 2009-04-23 12:43:42 +0500 |
commit | 5f9e40a5f8a469d87fb41002c18f3a41e9c4d6b3 (patch) | |
tree | 298f925620b41190de3964ef5aeb3d4c2359c97c | |
parent | e0526914b6acb91f8cf15bd536ad40e226158d1b (diff) | |
download | mariadb-git-5f9e40a5f8a469d87fb41002c18f3a41e9c4d6b3.tar.gz |
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:
test result
mysql-test/t/func_str.test:
test case
sql/item_strfunc.cc:
Added new parameter 'length' to SQL_CRYPT
sql/sql_crypt.cc:
Added new parameter 'length' to SQL_CRYPT
sql/sql_crypt.h:
Added new parameter 'length' to SQL_CRYPT
-rw-r--r-- | mysql-test/r/func_str.result | 14 | ||||
-rw-r--r-- | mysql-test/t/func_str.test | 12 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 4 | ||||
-rw-r--r-- | sql/sql_crypt.cc | 4 | ||||
-rw-r--r-- | 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 <derived2> 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 <derived2> 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); |