summaryrefslogtreecommitdiff
path: root/mysys_ssl
diff options
context:
space:
mode:
authorJan Lindström <jan.lindstrom@mariadb.com>2015-03-13 14:18:07 +0200
committerJan Lindström <jan.lindstrom@mariadb.com>2015-03-17 07:00:14 +0200
commita3e68b4a558e1dd0ff61e497316cb6a32d3de410 (patch)
tree8bf4bc26afe98529219198fb58c55a8d9438f212 /mysys_ssl
parent5e6f12366abb02143ef57b6ff99285d81e3b3a36 (diff)
downloadmariadb-git-a3e68b4a558e1dd0ff61e497316cb6a32d3de410.tar.gz
MDEV-7772: SIGSEGV on my_aes_encrypt_cbc when -DWITH_SSL=bundled
Two problems: - Read/Write outside of buffer at memcpy() because of incorrect parameters . OPENSSL_assert(EVP_CIPHER_CTX_iv_length(&ctx.ctx) == iv_length); // ECB does not use IV, thus incorrect assertion Added: mysql-test/include/encryption_algorithms.combinations to run tests with methods cbc, ecb and ctr in those systems where they are available (see suite.pm).
Diffstat (limited to 'mysys_ssl')
-rw-r--r--mysys_ssl/my_aes.cc36
1 files changed, 20 insertions, 16 deletions
diff --git a/mysys_ssl/my_aes.cc b/mysys_ssl/my_aes.cc
index 20bd03551c2..6486f7447c3 100644
--- a/mysys_ssl/my_aes.cc
+++ b/mysys_ssl/my_aes.cc
@@ -255,12 +255,12 @@ static int my_aes_encrypt_cbc(const uchar* source, uint32 source_length,
}
if (noPadding) {
- if (remaining_bytes!=0) {
- memcpy(dest + source_length, source + source_length, remaining_bytes);
- }
+ if (remaining_bytes!=0) {
+ /* Note that we moved the original pointers above */
+ memcpy(dest, source, remaining_bytes);
+ }
*dest_length = MY_AES_BLOCK_SIZE * (num_blocks) + remaining_bytes;
return AES_OK;
-
}
/* Encode the rest. We always have incomplete block */
@@ -383,12 +383,12 @@ static int my_aes_encrypt_ecb(const uchar* source, uint32 source_length,
}
if (noPadding) {
- if (remaining_bytes!=0) {
- memcpy(dest + source_length, source + source_length, remaining_bytes);
- }
- *dest_length = MY_AES_BLOCK_SIZE * (num_blocks) + remaining_bytes;
+ if (remaining_bytes!=0) {
+ /* Note that we moved the original pointers above */
+ memcpy(dest, source, remaining_bytes);
+ }
+ *dest_length = MY_AES_BLOCK_SIZE * (num_blocks) + remaining_bytes;
return AES_OK;
-
}
/* Encode the rest. We always have incomplete block */
@@ -430,7 +430,8 @@ static int my_aes_encrypt_ecb(const uchar* source, uint32 source_length,
}
EVP_CIPHER_CTX_key_length(&ctx.ctx);
OPENSSL_assert(EVP_CIPHER_CTX_key_length(&ctx.ctx) == key_length);
- OPENSSL_assert(EVP_CIPHER_CTX_iv_length(&ctx.ctx) == iv_length);
+ // ECB does not use IV
+ OPENSSL_assert(EVP_CIPHER_CTX_iv_length(&ctx.ctx) == 0);
OPENSSL_assert(EVP_CIPHER_CTX_block_size(&ctx.ctx) == 16);
if (! EVP_EncryptUpdate(&ctx.ctx, (unsigned char *) dest, &u_len,
(unsigned const char *) source, source_length))
@@ -438,9 +439,9 @@ static int my_aes_encrypt_ecb(const uchar* source, uint32 source_length,
if (! EVP_EncryptFinal_ex(&ctx.ctx, (unsigned char *) dest + u_len, &f_len))
return AES_BAD_DATA; /* Error */
- if (remaining_bytes!=0) {
- memcpy(dest + source_length, source + source_length, remaining_bytes);
- }
+ if (remaining_bytes!=0)
+ memcpy(dest + source_length, source + source_length, remaining_bytes);
+
*dest_length = (unsigned long int) (u_len + f_len + remaining_bytes);
return AES_OK;
@@ -524,7 +525,8 @@ static int my_aes_decrypt_cbc(const uchar* source, uint32 source_length,
if (noPadding) {
memcpy(dest, block, MY_AES_BLOCK_SIZE);
if (remaining_bytes!=0) {
- memcpy(dest + source_length, source + source_length, remaining_bytes);
+ /* Note that we have moved dest and source */
+ memcpy(dest + MY_AES_BLOCK_SIZE, source + MY_AES_BLOCK_SIZE, remaining_bytes);
}
*dest_length = MY_AES_BLOCK_SIZE * num_blocks + remaining_bytes;
return AES_OK;
@@ -656,7 +658,8 @@ static int my_aes_decrypt_ecb(const uchar* source, uint32 source_length,
if (noPadding) {
memcpy(dest, block, MY_AES_BLOCK_SIZE);
if (remaining_bytes!=0) {
- memcpy(dest + source_length, source + source_length, remaining_bytes);
+ /* Note that we have moved dest and source */
+ memcpy(dest + MY_AES_BLOCK_SIZE, source + MY_AES_BLOCK_SIZE, remaining_bytes);
}
*dest_length = MY_AES_BLOCK_SIZE * num_blocks + remaining_bytes;
return AES_OK;
@@ -699,7 +702,8 @@ static int my_aes_decrypt_ecb(const uchar* source, uint32 source_length,
EVP_CIPHER_CTX_set_padding(&ctx.ctx, 0);
}
OPENSSL_assert(EVP_CIPHER_CTX_key_length(&ctx.ctx) == key_length);
- OPENSSL_assert(EVP_CIPHER_CTX_iv_length(&ctx.ctx) == iv_length);
+ // ECB does not use IV
+ OPENSSL_assert(EVP_CIPHER_CTX_iv_length(&ctx.ctx) == 0);
OPENSSL_assert(EVP_CIPHER_CTX_block_size(&ctx.ctx) == 16);
if (! EVP_DecryptUpdate(&ctx.ctx, (unsigned char *) dest, &u_len,
(unsigned char *)source, source_length))