summaryrefslogtreecommitdiff
path: root/sql/item_strfunc.cc
diff options
context:
space:
mode:
authorunknown <evgen@moonbone.local>2006-05-28 22:01:38 +0400
committerunknown <evgen@moonbone.local>2006-05-28 22:01:38 +0400
commitfd7d4d742993cb33641565e5f9923ae6a21fdb61 (patch)
tree92cb12e483eb1ba657db44d5d64e5cd5abb98d52 /sql/item_strfunc.cc
parentc12d80151a6010e8dbb7138af09675749516dc15 (diff)
downloadmariadb-git-fd7d4d742993cb33641565e5f9923ae6a21fdb61.tar.gz
Fixed bug#15351: Wrong collation used for comparison of md5() and sha()
argument can lead to a wrong result. md5() and sha() functions treat their arguments as case sensitive strings. But when they are compared their arguments were compared as a case insensitive strings which leads to two functions with different arguments and thus different results to being identical. This can lead to a wrong decision made in the range optimizer and thus lead to a wrong result set. Item_func_md5::fix_length_and_dec() and Item_func_sha::fix_length_and_dec() functions now set binary collation on their arguments. sql/item_strfunc.cc: Fixed bug#15351: Wrong collation used for comparison of md5() and sha() argument can lead to a wrong result. Item_func_md5::fix_length_and_dec() and Item_func_sha::fix_length_and_dec() functions now set binary collation on their arguments. mysql-test/r/func_str.result: Added test case for the bug#15351: Wrong collation used for comparison of md5() and sha() argument can lead to a wrong result. mysql-test/t/func_str.test: Added test case for the bug#15351: Wrong collation used for comparison of md5() and sha() argument can lead to a wrong result.
Diffstat (limited to 'sql/item_strfunc.cc')
-rw-r--r--sql/item_strfunc.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index e74d0100b55..e817edac6c0 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -118,7 +118,15 @@ String *Item_func_md5::val_str(String *str)
void Item_func_md5::fix_length_and_dec()
{
- max_length=32;
+ max_length=32;
+ /*
+ The MD5() function treats its parameter as being a case sensitive. Thus
+ we set binary collation on it so different instances of MD5() will be
+ compared properly.
+ */
+ args[0]->collation.set(
+ get_charset_by_csname(args[0]->collation.collation->csname,
+ MY_CS_BINSORT,MYF(0)), DERIVATION_COERCIBLE);
}
@@ -159,7 +167,15 @@ String *Item_func_sha::val_str(String *str)
void Item_func_sha::fix_length_and_dec()
{
- max_length=SHA1_HASH_SIZE*2; // size of hex representation of hash
+ max_length=SHA1_HASH_SIZE*2; // size of hex representation of hash
+ /*
+ The SHA() function treats its parameter as being a case sensitive. Thus
+ we set binary collation on it so different instances of MD5() will be
+ compared properly.
+ */
+ args[0]->collation.set(
+ get_charset_by_csname(args[0]->collation.collation->csname,
+ MY_CS_BINSORT,MYF(0)), DERIVATION_COERCIBLE);
}