diff --git a/mysql-test/r/func_encrypt.result b/mysql-test/r/func_encrypt.result index 04af76429f8..2e5812eb44f 100644 --- a/mysql-test/r/func_encrypt.result +++ b/mysql-test/r/func_encrypt.result @@ -183,3 +183,15 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1003 select des_decrypt(des_encrypt('hello',4),'password2') AS `des_decrypt(des_encrypt("hello",4),'password2')`,des_decrypt(des_encrypt('hello','hidden')) AS `des_decrypt(des_encrypt("hello","hidden"))` +drop table if exists t1; +create table t1 (f1 smallint(6) default null, f2 mediumtext character set utf8) +engine=myisam default charset=latin1; +insert into t1 values (null,'contraction\'s'); +insert into t1 values (-15818,'requirement\'s'); +select encrypt(f1,f2) as a from t1,(select encrypt(f1,f2) as b from t1) a; +a +NULL +re3VF.eOzS/lg +NULL +re3VF.eOzS/lg +drop table t1; diff --git a/mysql-test/t/func_encrypt.test b/mysql-test/t/func_encrypt.test index bcf1e5a77f4..31cfae2be1d 100644 --- a/mysql-test/t/func_encrypt.test +++ b/mysql-test/t/func_encrypt.test @@ -88,3 +88,16 @@ select hex(des_decrypt(des_encrypt("hello","hidden"))); explain extended select des_decrypt(des_encrypt("hello",4),'password2'), des_decrypt(des_encrypt("hello","hidden")); # End of 4.1 tests + +# +# Bug#44365 valgrind warnings with encrypt() function +# +--disable_warnings +drop table if exists t1; +--enable_warnings +create table t1 (f1 smallint(6) default null, f2 mediumtext character set utf8) +engine=myisam default charset=latin1; +insert into t1 values (null,'contraction\'s'); +insert into t1 values (-15818,'requirement\'s'); +select encrypt(f1,f2) as a from t1,(select encrypt(f1,f2) as b from t1) a; +drop table t1; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 5bb561fc1a9..267036e4a3d 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1693,10 +1693,10 @@ String *Item_func_encrypt::val_str(String *str) String *salt_str=args[1]->val_str(&tmp_value); if ((null_value= (args[1]->null_value || salt_str->length() < 2))) return 0; - salt_ptr= salt_str->c_ptr(); + salt_ptr= salt_str->c_ptr_safe(); } pthread_mutex_lock(&LOCK_crypt); - char *tmp= crypt(res->c_ptr(),salt_ptr); + char *tmp= crypt(res->c_ptr_safe(),salt_ptr); if (!tmp) { pthread_mutex_unlock(&LOCK_crypt);