Skip to content

Commit

Permalink
Fix bug #72455: Heap Overflow due to integer overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev committed Jun 21, 2016
1 parent f6aef68 commit 6c5211a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ext/mcrypt/mcrypt.c
Expand Up @@ -692,6 +692,10 @@ PHP_FUNCTION(mcrypt_generic)
if (mcrypt_enc_is_block_mode(pm->td) == 1) { /* It's a block algorithm */
block_size = mcrypt_enc_get_block_size(pm->td);
data_size = (((data_len - 1) / block_size) + 1) * block_size;
if (data_size <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Integer overflow in data size");
RETURN_FALSE;
}
data_s = emalloc(data_size + 1);
memset(data_s, 0, data_size);
memcpy(data_s, data, data_len);
Expand Down Expand Up @@ -737,6 +741,10 @@ PHP_FUNCTION(mdecrypt_generic)
if (mcrypt_enc_is_block_mode(pm->td) == 1) { /* It's a block algorithm */
block_size = mcrypt_enc_get_block_size(pm->td);
data_size = (((data_len - 1) / block_size) + 1) * block_size;
if (data_size <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Integer overflow in data size");
RETURN_FALSE;
}
data_s = emalloc(data_size + 1);
memset(data_s, 0, data_size);
memcpy(data_s, data, data_len);
Expand Down

0 comments on commit 6c5211a

Please sign in to comment.