From e7620ce4ce93c9c449b6d4ccffb7a6054a40deb4 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 19 Jun 2015 18:05:10 +0200 Subject: [PATCH] MDEV-8281 aes_decrypt crashes in block_crypt() fix aes_decrypt of yassl to support zero-length input --- mysql-test/r/func_str.result | 3 +++ mysql-test/t/func_str.test | 1 + mysys_ssl/my_crypt.cc | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index bc5f6951184..06d748fa72f 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -264,6 +264,9 @@ NULL select aes_decrypt(aes_encrypt("","a"),"a"); aes_decrypt(aes_encrypt("","a"),"a") +select aes_decrypt("", "a"); +aes_decrypt("", "a") +NULL select repeat('monty',5),concat('*',space(5),'*'); repeat('monty',5) concat('*',space(5),'*') montymontymontymontymonty * * diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 6369609bea3..95b742d3545 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -105,6 +105,7 @@ select aes_decrypt(NULL,"a"); select aes_decrypt("a",NULL); select aes_decrypt("a","a"); select aes_decrypt(aes_encrypt("","a"),"a"); +select aes_decrypt("", "a"); select repeat('monty',5),concat('*',space(5),'*'); select reverse('abc'),reverse('abcd'); select rpad('a',4,'1'),rpad('a',4,'12'),rpad('abcd',3,'12'), rpad(11, 10 , 22), rpad("ab", 10, 22); diff --git a/mysys_ssl/my_crypt.cc b/mysys_ssl/my_crypt.cc index 9f37883a9b8..dc3c4f63bdb 100644 --- a/mysys_ssl/my_crypt.cc +++ b/mysys_ssl/my_crypt.cc @@ -104,7 +104,7 @@ static int block_crypt(CipherMode cipher, Dir dir, } else { - int n= dest[source_length - 1]; + int n= source_length ? dest[source_length - 1] : 0; if (tail || n == 0 || n > MY_AES_BLOCK_SIZE) return MY_AES_BAD_DATA; *dest_length-= n;