summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mysql.com>2010-07-07 10:38:11 +0400
committerAlexander Barkov <bar@mysql.com>2010-07-07 10:38:11 +0400
commit00e86d01a72c539b915e07f4b7b8fe218433fd60 (patch)
treee872e3c1b1d8935b62347e5c4fd395d237b68567
parent72bb9b7acbacc20172512184dc2724fccbc7a741 (diff)
downloadmariadb-git-00e86d01a72c539b915e07f4b7b8fe218433fd60.tar.gz
Bug#54661 sha2() returns BINARY result
Problem: sha2() reported its result as BINARY Fix: - Inheriting Item_func_sha2 from Item_str_ascii_func - Setting max_length via fix_length_and_charset() instead of direct assignment. - Adding tests
-rw-r--r--mysql-test/r/func_digest.result21
-rw-r--r--mysql-test/t/func_digest.test13
-rw-r--r--sql/item_strfunc.cc10
-rw-r--r--sql/item_strfunc.h13
4 files changed, 44 insertions, 13 deletions
diff --git a/mysql-test/r/func_digest.result b/mysql-test/r/func_digest.result
index ff3a4dcf79a..095b69363ce 100644
--- a/mysql-test/r/func_digest.result
+++ b/mysql-test/r/func_digest.result
@@ -1405,3 +1405,24 @@ LENGTH(SHA2( 'size', 384 )) / 2 * 8 = 384
SELECT LENGTH(SHA2( 'computed', 512 )) / 2 * 8 = 512;
LENGTH(SHA2( 'computed', 512 )) / 2 * 8 = 512
1
+#
+# Bug#54661 sha2() returns BINARY result
+#
+SET NAMES binary;
+SELECT sha2('1',224);
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def sha2('1',224) 253 56 56 Y 128 31 63
+sha2('1',224)
+e25388fde8290dc286a6164fa2d97e551b53498dcbf7bc378eb1f178
+SET NAMES utf8;
+SELECT sha2('1',224);
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def sha2('1',224) 253 168 56 Y 0 31 33
+sha2('1',224)
+e25388fde8290dc286a6164fa2d97e551b53498dcbf7bc378eb1f178
+SET NAMES latin1;
+SELECT sha2('1',224);
+Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
+def sha2('1',224) 253 56 56 Y 0 31 8
+sha2('1',224)
+e25388fde8290dc286a6164fa2d97e551b53498dcbf7bc378eb1f178
diff --git a/mysql-test/t/func_digest.test b/mysql-test/t/func_digest.test
index 4020ef0f4fc..81f19c7e091 100644
--- a/mysql-test/t/func_digest.test
+++ b/mysql-test/t/func_digest.test
@@ -481,3 +481,16 @@ SELECT LENGTH(SHA2( '', 224 )) / 2 * 8 = 224;
SELECT LENGTH(SHA2( 'any', 256 )) / 2 * 8 = 256;
SELECT LENGTH(SHA2( 'size', 384 )) / 2 * 8 = 384;
SELECT LENGTH(SHA2( 'computed', 512 )) / 2 * 8 = 512;
+
+--echo #
+--echo # Bug#54661 sha2() returns BINARY result
+--echo #
+--enable_metadata
+SET NAMES binary;
+SELECT sha2('1',224);
+SET NAMES utf8;
+SELECT sha2('1',224);
+SET NAMES latin1;
+SELECT sha2('1',224);
+--disable_metadata
+
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 61febb01e93..2a9eef2298d 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -242,7 +242,7 @@ void Item_func_sha::fix_length_and_dec()
fix_length_and_charset(SHA1_HASH_SIZE * 2, default_charset());
}
-String *Item_func_sha2::val_str(String *str)
+String *Item_func_sha2::val_str_ascii(String *str)
{
DBUG_ASSERT(fixed == 1);
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
@@ -338,19 +338,19 @@ void Item_func_sha2::fix_length_and_dec()
switch (sha_variant) {
#ifndef OPENSSL_NO_SHA512
case 512:
- max_length= SHA512_DIGEST_LENGTH*2;
+ fix_length_and_charset(SHA512_DIGEST_LENGTH * 2, default_charset());
break;
case 384:
- max_length= SHA384_DIGEST_LENGTH*2;
+ fix_length_and_charset(SHA384_DIGEST_LENGTH * 2, default_charset());
break;
#endif
#ifndef OPENSSL_NO_SHA256
case 256:
case 0: // SHA-256 is the default
- max_length= SHA256_DIGEST_LENGTH*2;
+ fix_length_and_charset(SHA256_DIGEST_LENGTH * 2, default_charset());
break;
case 224:
- max_length= SHA224_DIGEST_LENGTH*2;
+ fix_length_and_charset(SHA224_DIGEST_LENGTH * 2, default_charset());
break;
#endif
default:
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 2a34babae87..df794ecaaf4 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -82,16 +82,13 @@ public:
const char *func_name() const { return "sha"; }
};
-class Item_func_sha2 :public Item_str_func
+class Item_func_sha2 :public Item_str_ascii_func
{
public:
- Item_func_sha2(Item *a, Item *b) :Item_str_func(a, b)
- {
- collation.set(&my_charset_bin);
- }
- String *val_str(String *);
- void fix_length_and_dec();
- const char *func_name() const { return "sha2"; }
+ Item_func_sha2(Item *a, Item *b) :Item_str_ascii_func(a, b) {}
+ String *val_str_ascii(String *);
+ void fix_length_and_dec();
+ const char *func_name() const { return "sha2"; }
};
class Item_func_aes_encrypt :public Item_str_func