com php-src: fix bug #73275 - crash in openssl_encrypt func tion: ext/openssl/openssl.c
| From: | Stanislav Malyshev | Date: | Tue, 11 Oct 2016 20:19:20 +0000 |
| Subject: | com php-src: fix bug #73275 - crash in openssl_encrypt func tion: ext/openssl/openssl.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94921@lists.php.net to get a copy of this message | ||
Commit: 8822f7c9f0be2f591f8fa58834c5e1bc529b24dc
Author: Stanislav Malyshev <stas@php.net> Tue, 11 Oct 2016 13:19:20 -0700
Parents: 8259130b6bc752968856b352c9e7f8e03a8c0a8e
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8822f7c9f0be2f591f8fa58834c5e1bc529b24dc
Log:
fix bug #73275 - crash in openssl_encrypt function
Bugs:
https://bugs.php.net/73275
Changed paths:
M ext/openssl/openssl.c
Diff:
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 844132b..33593e7 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -5260,7 +5260,7 @@ PHP_FUNCTION(openssl_encrypt)
free_iv = php_openssl_validate_iv(&iv, &iv_len, max_iv_len TSRMLS_CC);
outlen = data_len + EVP_CIPHER_block_size(cipher_type);
- outbuf = emalloc(outlen + 1);
+ outbuf = safe_emalloc(outlen, 1, 1);
EVP_EncryptInit(&cipher_ctx, cipher_type, NULL, NULL);
if (password_len > keylen) {
@@ -5278,14 +5278,18 @@ PHP_FUNCTION(openssl_encrypt)
outlen += i;
if (options & OPENSSL_RAW_DATA) {
outbuf[outlen] = '\0';
- RETVAL_STRINGL((char *)outbuf, outlen, 0);
+ RETVAL_STRINGL_CHECK((char *)outbuf, outlen, 0);
} else {
int base64_str_len;
char *base64_str;
base64_str = (char*)php_base64_encode(outbuf, outlen, &base64_str_len);
efree(outbuf);
- RETVAL_STRINGL(base64_str, base64_str_len, 0);
+ if (!base64_str) {
+ RETVAL_FALSE;
+ } else {
+ RETVAL_STRINGL(base64_str, base64_str_len, 0);
+ }
}
} else {
efree(outbuf);